    {-# LINE 2 "./Graphics/UI/Gtk/OpenGL/DrawingArea.chs" #-}
    -- -*-haskell-*-
    -- GIMP Toolkit (GTK) OpenGL Extension: DrawingArea Widget
    --
    -- Author : Duncan Coutts
    --
    -- Created: 9 June 2005
    --
    -- Copyright (C) 2005 Duncan Coutts
    --
    -- 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)
    --
    --
    --
    module Graphics.UI.Gtk.OpenGL.DrawingArea (

    -- * Class Hierarchy
    -- |
    -- @
    -- | 'GObject'
    -- | +----'Object'
    -- | +----'Widget'
    -- | +----'DrawingArea'
    -- | +----GLDrawingArea
    -- @

    -- * Types
      GLDrawingArea,

    -- * Constructors
      glDrawingAreaNew,

    -- * Methods
      withGLDrawingArea,
      glDrawingAreaGetGLConfig,
      glDrawingAreaGetGLContext,
      glDrawingAreaGetGLWindow,
      ) where

    import Control.Monad (liftM)

    import System.Glib.FFI
    import System.Glib.GObject (makeNewGObject)
    import Graphics.UI.Gtk.OpenGL.Types
    {-# LINE 58 "./Graphics/UI/Gtk/OpenGL/DrawingArea.chs" #-}
    import Graphics.UI.Gtk.Misc.DrawingArea (drawingAreaNew)
    import Graphics.UI.Gtk.OpenGL.Drawable (glDrawableGLBegin, glDrawableWaitGL, glDrawableGLEnd)
    import Graphics.UI.Gtk.OpenGL.Window ()
    import Graphics.UI.Gtk.OpenGL.Context (GLRenderType(..))

    {-# LINE 64 "./Graphics/UI/Gtk/OpenGL/DrawingArea.chs" #-}

    --------------------
    -- Types

    newtype GLDrawingArea = GLDrawingArea DrawingArea

    instance DrawingAreaClass GLDrawingArea
    instance WidgetClass GLDrawingArea
    instance ObjectClass GLDrawingArea
    instance GObjectClass GLDrawingArea where
      toGObject (GLDrawingArea gd) = toGObject gd
      unsafeCastGObject = GLDrawingArea . unsafeCastGObject

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

    glDrawingAreaNew :: GLConfig -> IO GLDrawingArea
    glDrawingAreaNew glconfig = do
      drawingArea <- drawingAreaNew
      widgetSetGLCapability drawingArea glconfig Nothing True RGBAType
      return (GLDrawingArea drawingArea)

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

    withGLDrawingArea :: GLDrawingArea -> (GLWindow -> IO a) -> IO a
    withGLDrawingArea glDrawingArea glAction = do
      glcontext <- glDrawingAreaGetGLContext glDrawingArea
      glwindow <- glDrawingAreaGetGLWindow glDrawingArea
      glDrawableGLBegin glwindow glcontext
      result <- glAction glwindow
      glDrawableWaitGL glwindow
      glDrawableGLEnd glwindow
      return result

    -- |
    --
    glDrawingAreaGetGLConfig :: GLDrawingArea -> IO GLConfig
    glDrawingAreaGetGLConfig (GLDrawingArea widget) =
      makeNewGObject mkGLConfig $
      (\(Widget arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_widget_get_gl_config argPtr1)
    {-# LINE 107 "./Graphics/UI/Gtk/OpenGL/DrawingArea.chs" #-}
        (toWidget widget)

    -- |
    --
    glDrawingAreaGetGLContext :: GLDrawingArea -> IO GLContext
    glDrawingAreaGetGLContext (GLDrawingArea widget) =
      makeNewGObject mkGLContext $
      (\(Widget arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_widget_get_gl_context argPtr1)
    {-# LINE 115 "./Graphics/UI/Gtk/OpenGL/DrawingArea.chs" #-}
        (toWidget widget)

    -- |
    --
    glDrawingAreaGetGLWindow :: GLDrawingArea -> IO GLWindow
    glDrawingAreaGetGLWindow (GLDrawingArea widget) =
      makeNewGObject mkGLWindow $
      (\(Widget arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_widget_get_gl_window argPtr1)
    {-# LINE 123 "./Graphics/UI/Gtk/OpenGL/DrawingArea.chs" #-}
        (toWidget widget)

    -- |
    --
    widgetSetGLCapability
     :: WidgetClass widget
     => widget
     -> GLConfig
     -> Maybe GLContext
     -> Bool
     -> GLRenderType
     -> IO Bool
    widgetSetGLCapability widget glconfig shareList direct renderType =
      liftM toBool $
      (\(Widget arg1) (GLConfig arg2) (GLContext arg3) arg4 arg5 -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->withForeignPtr arg3 $ \argPtr3 ->gtk_widget_set_gl_capability argPtr1 argPtr2 argPtr3 arg4 arg5)
    {-# LINE 138 "./Graphics/UI/Gtk/OpenGL/DrawingArea.chs" #-}
        (toWidget widget)
        (toGLConfig glconfig)
        (maybe (GLContext nullForeignPtr) toGLContext shareList)
        (fromBool direct)
        ((fromIntegral . fromEnum) renderType)

    foreign import ccall safe "gtk_widget_get_gl_config"
      gtk_widget_get_gl_config :: ((Ptr Widget) -> (IO (Ptr GLConfig)))

    foreign import ccall safe "gtk_widget_get_gl_context"
      gtk_widget_get_gl_context :: ((Ptr Widget) -> (IO (Ptr GLContext)))

    foreign import ccall safe "gtk_widget_get_gl_window"
      gtk_widget_get_gl_window :: ((Ptr Widget) -> (IO (Ptr GLWindow)))

    foreign import ccall safe "gtk_widget_set_gl_capability"
      gtk_widget_set_gl_capability :: ((Ptr Widget) -> ((Ptr GLConfig) -> ((Ptr GLContext) -> (CInt -> (CInt -> (IO CInt))))))