{-# LINE 2 "./Graphics/UI/Gtk/Misc/Viewport.chs" #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Widget Viewport
--
-- Author : Axel Simon
--
-- Created: 23 May 2001
--
-- Copyright (C) 1999-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.
--
-- Issues:
--
-- The binding of this widget is superfluous as far as I can tell.
--
-- The only signal this widget registers is \"set-scroll-adjustments\". It is
-- not bound because it is meant to be received by the 'Viewport'
-- and sent by 'ScrolledWindow'.
--
-- |
-- Maintainer : gtk2hs-users@lists.sourceforge.net
-- Stability : provisional
-- Portability : portable (depends on GHC)
--
-- An adapter which makes widgets scrollable
--
module Graphics.UI.Gtk.Misc.Viewport (
-- * Detail
--
-- | A 'Viewport' is a helper widget that adds Adjustment slots to a
-- widget, i.e. the widget becomes scrollable. It can then be put into
-- 'ScrolledWindow' and will behave as expected.

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

-- * Types
  Viewport,
  ViewportClass,
  ShadowType(..),
  castToViewport, gTypeViewport,
  toViewport,

-- * Constructors
  viewportNew,

-- * Methods
  viewportGetHAdjustment,
  viewportGetVAdjustment,
  viewportSetHAdjustment,
  viewportSetVAdjustment,
  viewportSetShadowType,
  viewportGetShadowType,

  viewportGetBinWindow,


  viewportGetViewWindow,


-- * Attributes
  viewportHAdjustment,
  viewportVAdjustment,
  viewportShadowType,
  ) where

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

import System.Glib.FFI
import System.Glib.Attributes
import Graphics.UI.Gtk.Abstract.Object (makeNewObject)
import Graphics.UI.Gtk.Types
{-# LINE 91 "./Graphics/UI/Gtk/Misc/Viewport.chs" #-}
import Graphics.UI.Gtk.General.Enums (ShadowType(..))


{-# LINE 94 "./Graphics/UI/Gtk/Misc/Viewport.chs" #-}

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

-- | Creates a new 'Viewport' with the given adjustments.
--
viewportNew ::
    Maybe Adjustment -- ^ @hadjustment@ - horizontal adjustment.
 -> Maybe Adjustment -- ^ @vadjustment@ - vertical adjustment.
 -> IO Viewport
viewportNew :: Maybe Adjustment -> Maybe Adjustment -> IO Viewport
viewportNew Maybe Adjustment
hadjustment Maybe Adjustment
vadjustment =
  (ForeignPtr Viewport -> Viewport, FinalizerPtr Viewport)
-> IO (Ptr Viewport) -> IO Viewport
forall obj.
ObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
makeNewObject (ForeignPtr Viewport -> Viewport, FinalizerPtr Viewport)
forall {a}. (ForeignPtr Viewport -> Viewport, FinalizerPtr a)
mkViewport (IO (Ptr Viewport) -> IO Viewport)
-> IO (Ptr Viewport) -> IO Viewport
forall a b. (a -> b) -> a -> b
$
  (Ptr Widget -> Ptr Viewport)
-> IO (Ptr Widget) -> IO (Ptr Viewport)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Ptr Widget -> Ptr Viewport
forall a b. Ptr a -> Ptr b
castPtr :: Ptr Widget -> Ptr Viewport) (IO (Ptr Widget) -> IO (Ptr Viewport))
-> IO (Ptr Widget) -> IO (Ptr Viewport)
forall a b. (a -> b) -> a -> b
$
  (\(Adjustment ForeignPtr Adjustment
arg1) (Adjustment ForeignPtr Adjustment
arg2) -> ForeignPtr Adjustment
-> (Ptr Adjustment -> IO (Ptr Widget)) -> IO (Ptr Widget)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Adjustment
arg1 ((Ptr Adjustment -> IO (Ptr Widget)) -> IO (Ptr Widget))
-> (Ptr Adjustment -> IO (Ptr Widget)) -> IO (Ptr Widget)
forall a b. (a -> b) -> a -> b
$ \Ptr Adjustment
argPtr1 ->ForeignPtr Adjustment
-> (Ptr Adjustment -> IO (Ptr Widget)) -> IO (Ptr Widget)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Adjustment
arg2 ((Ptr Adjustment -> IO (Ptr Widget)) -> IO (Ptr Widget))
-> (Ptr Adjustment -> IO (Ptr Widget)) -> IO (Ptr Widget)
forall a b. (a -> b) -> a -> b
$ \Ptr Adjustment
argPtr2 ->Ptr Adjustment -> Ptr Adjustment -> IO (Ptr Widget)
gtk_viewport_new Ptr Adjustment
argPtr1 Ptr Adjustment
argPtr2)
{-# LINE 108 "./Graphics/UI/Gtk/Misc/Viewport.chs" #-}
    (fromMaybe (Adjustment nullForeignPtr) hadjustment)
    (Adjustment -> Maybe Adjustment -> Adjustment
forall a. a -> Maybe a -> a
fromMaybe (ForeignPtr Adjustment -> Adjustment
Adjustment ForeignPtr Adjustment
forall a. ForeignPtr a
nullForeignPtr) Maybe Adjustment
vadjustment)

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

-- | Returns the horizontal adjustment of the viewport.
--
viewportGetHAdjustment :: ViewportClass self => self -> IO Adjustment
viewportGetHAdjustment :: forall self. ViewportClass self => self -> IO Adjustment
viewportGetHAdjustment self
self =
  (ForeignPtr Adjustment -> Adjustment, FinalizerPtr Adjustment)
-> IO (Ptr Adjustment) -> IO Adjustment
forall obj.
ObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
makeNewObject (ForeignPtr Adjustment -> Adjustment, FinalizerPtr Adjustment)
forall {a}. (ForeignPtr Adjustment -> Adjustment, FinalizerPtr a)
mkAdjustment (IO (Ptr Adjustment) -> IO Adjustment)
-> IO (Ptr Adjustment) -> IO Adjustment
forall a b. (a -> b) -> a -> b
$
  (\(Viewport ForeignPtr Viewport
arg1) -> ForeignPtr Viewport
-> (Ptr Viewport -> IO (Ptr Adjustment)) -> IO (Ptr Adjustment)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Viewport
arg1 ((Ptr Viewport -> IO (Ptr Adjustment)) -> IO (Ptr Adjustment))
-> (Ptr Viewport -> IO (Ptr Adjustment)) -> IO (Ptr Adjustment)
forall a b. (a -> b) -> a -> b
$ \Ptr Viewport
argPtr1 ->Ptr Viewport -> IO (Ptr Adjustment)
gtk_viewport_get_hadjustment Ptr Viewport
argPtr1)
{-# LINE 120 "./Graphics/UI/Gtk/Misc/Viewport.chs" #-}
    (toViewport self)

-- | Returns the vertical adjustment of the viewport.
--
viewportGetVAdjustment :: ViewportClass self => self -> IO Adjustment
viewportGetVAdjustment :: forall self. ViewportClass self => self -> IO Adjustment
viewportGetVAdjustment self
self =
  (ForeignPtr Adjustment -> Adjustment, FinalizerPtr Adjustment)
-> IO (Ptr Adjustment) -> IO Adjustment
forall obj.
ObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
makeNewObject (ForeignPtr Adjustment -> Adjustment, FinalizerPtr Adjustment)
forall {a}. (ForeignPtr Adjustment -> Adjustment, FinalizerPtr a)
mkAdjustment (IO (Ptr Adjustment) -> IO Adjustment)
-> IO (Ptr Adjustment) -> IO Adjustment
forall a b. (a -> b) -> a -> b
$
  (\(Viewport ForeignPtr Viewport
arg1) -> ForeignPtr Viewport
-> (Ptr Viewport -> IO (Ptr Adjustment)) -> IO (Ptr Adjustment)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Viewport
arg1 ((Ptr Viewport -> IO (Ptr Adjustment)) -> IO (Ptr Adjustment))
-> (Ptr Viewport -> IO (Ptr Adjustment)) -> IO (Ptr Adjustment)
forall a b. (a -> b) -> a -> b
$ \Ptr Viewport
argPtr1 ->Ptr Viewport -> IO (Ptr Adjustment)
gtk_viewport_get_vadjustment Ptr Viewport
argPtr1)
{-# LINE 128 "./Graphics/UI/Gtk/Misc/Viewport.chs" #-}
    (toViewport self)

-- | Sets the horizontal adjustment of the viewport.
--
viewportSetHAdjustment :: ViewportClass self => self -> Adjustment -> IO ()
viewportSetHAdjustment :: forall self. ViewportClass self => self -> Adjustment -> IO ()
viewportSetHAdjustment self
self Adjustment
adjustment =
  (\(Viewport ForeignPtr Viewport
arg1) (Adjustment ForeignPtr Adjustment
arg2) -> ForeignPtr Viewport -> (Ptr Viewport -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Viewport
arg1 ((Ptr Viewport -> IO ()) -> IO ())
-> (Ptr Viewport -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Viewport
argPtr1 ->ForeignPtr Adjustment -> (Ptr Adjustment -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Adjustment
arg2 ((Ptr Adjustment -> IO ()) -> IO ())
-> (Ptr Adjustment -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Adjustment
argPtr2 ->Ptr Viewport -> Ptr Adjustment -> IO ()
gtk_viewport_set_hadjustment Ptr Viewport
argPtr1 Ptr Adjustment
argPtr2)
{-# LINE 135 "./Graphics/UI/Gtk/Misc/Viewport.chs" #-}
    (toViewport self)
    Adjustment
adjustment

-- | Sets the vertical adjustment of the viewport.
--
viewportSetVAdjustment :: ViewportClass self => self -> Adjustment -> IO ()
viewportSetVAdjustment :: forall self. ViewportClass self => self -> Adjustment -> IO ()
viewportSetVAdjustment self
self Adjustment
adjustment =
  (\(Viewport ForeignPtr Viewport
arg1) (Adjustment ForeignPtr Adjustment
arg2) -> ForeignPtr Viewport -> (Ptr Viewport -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Viewport
arg1 ((Ptr Viewport -> IO ()) -> IO ())
-> (Ptr Viewport -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Viewport
argPtr1 ->ForeignPtr Adjustment -> (Ptr Adjustment -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Adjustment
arg2 ((Ptr Adjustment -> IO ()) -> IO ())
-> (Ptr Adjustment -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Adjustment
argPtr2 ->Ptr Viewport -> Ptr Adjustment -> IO ()
gtk_viewport_set_vadjustment Ptr Viewport
argPtr1 Ptr Adjustment
argPtr2)
{-# LINE 143 "./Graphics/UI/Gtk/Misc/Viewport.chs" #-}
    (toViewport self)
    Adjustment
adjustment

-- | Sets the shadow type of the viewport.
--
viewportSetShadowType :: ViewportClass self => self
 -> ShadowType -- ^ @type@ - the new shadow type.
 -> IO ()
viewportSetShadowType :: forall self. ViewportClass self => self -> ShadowType -> IO ()
viewportSetShadowType self
self ShadowType
type_ =
  (\(Viewport ForeignPtr Viewport
arg1) CInt
arg2 -> ForeignPtr Viewport -> (Ptr Viewport -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Viewport
arg1 ((Ptr Viewport -> IO ()) -> IO ())
-> (Ptr Viewport -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Viewport
argPtr1 ->Ptr Viewport -> CInt -> IO ()
gtk_viewport_set_shadow_type Ptr Viewport
argPtr1 CInt
arg2)
{-# LINE 153 "./Graphics/UI/Gtk/Misc/Viewport.chs" #-}
    (toViewport self)
    ((Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (ShadowType -> Int) -> ShadowType -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShadowType -> Int
forall a. Enum a => a -> Int
fromEnum) ShadowType
type_)

-- | Gets the shadow type of the 'Viewport'. See 'viewportSetShadowType'.
--
viewportGetShadowType :: ViewportClass self => self
 -> IO ShadowType -- ^ returns the shadow type
viewportGetShadowType :: forall self. ViewportClass self => self -> IO ShadowType
viewportGetShadowType self
self =
  (CInt -> ShadowType) -> IO CInt -> IO ShadowType
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Int -> ShadowType
forall a. Enum a => Int -> a
toEnum (Int -> ShadowType) -> (CInt -> Int) -> CInt -> ShadowType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral) (IO CInt -> IO ShadowType) -> IO CInt -> IO ShadowType
forall a b. (a -> b) -> a -> b
$
  (\(Viewport ForeignPtr Viewport
arg1) -> ForeignPtr Viewport -> (Ptr Viewport -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Viewport
arg1 ((Ptr Viewport -> IO CInt) -> IO CInt)
-> (Ptr Viewport -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr Viewport
argPtr1 ->Ptr Viewport -> IO CInt
gtk_viewport_get_shadow_type Ptr Viewport
argPtr1)
{-# LINE 163 "./Graphics/UI/Gtk/Misc/Viewport.chs" #-}
    (toViewport self)


-- | Gets the bin window of the 'Viewport'.
--
-- * Available since Gtk version 2.20
--
viewportGetBinWindow :: ViewportClass self => self -> IO DrawWindow
viewportGetBinWindow :: forall self. ViewportClass self => self -> IO DrawWindow
viewportGetBinWindow self
self =
    (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 DrawWindow)
-> IO (Ptr DrawWindow) -> IO DrawWindow
forall a b. (a -> b) -> a -> b
$
    (\(Viewport ForeignPtr Viewport
arg1) -> ForeignPtr Viewport
-> (Ptr Viewport -> IO (Ptr DrawWindow)) -> IO (Ptr DrawWindow)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Viewport
arg1 ((Ptr Viewport -> IO (Ptr DrawWindow)) -> IO (Ptr DrawWindow))
-> (Ptr Viewport -> IO (Ptr DrawWindow)) -> IO (Ptr DrawWindow)
forall a b. (a -> b) -> a -> b
$ \Ptr Viewport
argPtr1 ->Ptr Viewport -> IO (Ptr DrawWindow)
gtk_viewport_get_bin_window Ptr Viewport
argPtr1)
{-# LINE 174 "./Graphics/UI/Gtk/Misc/Viewport.chs" #-}
      (toViewport self)



-- | Gets the view window of the 'Viewport'.
--
-- * Available since Gtk+ version 2.22
--
viewportGetViewWindow :: ViewportClass self => self -> IO DrawWindow
viewportGetViewWindow :: forall self. ViewportClass self => self -> IO DrawWindow
viewportGetViewWindow self
self =
    (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 DrawWindow)
-> IO (Ptr DrawWindow) -> IO DrawWindow
forall a b. (a -> b) -> a -> b
$
    (\(Viewport ForeignPtr Viewport
arg1) -> ForeignPtr Viewport
-> (Ptr Viewport -> IO (Ptr DrawWindow)) -> IO (Ptr DrawWindow)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Viewport
arg1 ((Ptr Viewport -> IO (Ptr DrawWindow)) -> IO (Ptr DrawWindow))
-> (Ptr Viewport -> IO (Ptr DrawWindow)) -> IO (Ptr DrawWindow)
forall a b. (a -> b) -> a -> b
$ \Ptr Viewport
argPtr1 ->Ptr Viewport -> IO (Ptr DrawWindow)
gtk_viewport_get_view_window Ptr Viewport
argPtr1)
{-# LINE 186 "./Graphics/UI/Gtk/Misc/Viewport.chs" #-}
      (toViewport self)


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

-- | The 'Adjustment' that determines the values of the horizontal position
-- for this viewport.
--
viewportHAdjustment :: ViewportClass self => Attr self Adjustment
viewportHAdjustment :: forall self. ViewportClass self => Attr self Adjustment
viewportHAdjustment = (self -> IO Adjustment)
-> (self -> Adjustment -> IO ())
-> ReadWriteAttr self Adjustment Adjustment
forall o a b.
(o -> IO a) -> (o -> b -> IO ()) -> ReadWriteAttr o a b
newAttr
  self -> IO Adjustment
forall self. ViewportClass self => self -> IO Adjustment
viewportGetHAdjustment
  self -> Adjustment -> IO ()
forall self. ViewportClass self => self -> Adjustment -> IO ()
viewportSetHAdjustment

-- | The 'Adjustment' that determines the values of the vertical position for
-- this viewport.
--
viewportVAdjustment :: ViewportClass self => Attr self Adjustment
viewportVAdjustment :: forall self. ViewportClass self => Attr self Adjustment
viewportVAdjustment = (self -> IO Adjustment)
-> (self -> Adjustment -> IO ())
-> ReadWriteAttr self Adjustment Adjustment
forall o a b.
(o -> IO a) -> (o -> b -> IO ()) -> ReadWriteAttr o a b
newAttr
  self -> IO Adjustment
forall self. ViewportClass self => self -> IO Adjustment
viewportGetVAdjustment
  self -> Adjustment -> IO ()
forall self. ViewportClass self => self -> Adjustment -> IO ()
viewportSetVAdjustment

-- | Determines how the shadowed box around the viewport is drawn.
--
-- Default value: 'ShadowIn'
--
viewportShadowType :: ViewportClass self => Attr self ShadowType
viewportShadowType :: forall self. ViewportClass self => Attr self ShadowType
viewportShadowType = (self -> IO ShadowType)
-> (self -> ShadowType -> IO ())
-> ReadWriteAttr self ShadowType ShadowType
forall o a b.
(o -> IO a) -> (o -> b -> IO ()) -> ReadWriteAttr o a b
newAttr
  self -> IO ShadowType
forall self. ViewportClass self => self -> IO ShadowType
viewportGetShadowType
  self -> ShadowType -> IO ()
forall self. ViewportClass self => self -> ShadowType -> IO ()
viewportSetShadowType

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

foreign import ccall unsafe "gtk_viewport_new"
  gtk_viewport_new :: ((Ptr Adjustment) -> ((Ptr Adjustment) -> (IO (Ptr Widget))))

foreign import ccall unsafe "gtk_viewport_get_hadjustment"
  gtk_viewport_get_hadjustment :: ((Ptr Viewport) -> (IO (Ptr Adjustment)))

foreign import ccall unsafe "gtk_viewport_get_vadjustment"
  gtk_viewport_get_vadjustment :: ((Ptr Viewport) -> (IO (Ptr Adjustment)))

foreign import ccall safe "gtk_viewport_set_hadjustment"
  gtk_viewport_set_hadjustment :: ((Ptr Viewport) -> ((Ptr Adjustment) -> (IO ())))

foreign import ccall safe "gtk_viewport_set_vadjustment"
  gtk_viewport_set_vadjustment :: ((Ptr Viewport) -> ((Ptr Adjustment) -> (IO ())))

foreign import ccall safe "gtk_viewport_set_shadow_type"
  gtk_viewport_set_shadow_type :: ((Ptr Viewport) -> (CInt -> (IO ())))

foreign import ccall unsafe "gtk_viewport_get_shadow_type"
  gtk_viewport_get_shadow_type :: ((Ptr Viewport) -> (IO CInt))

foreign import ccall safe "gtk_viewport_get_bin_window"
  gtk_viewport_get_bin_window :: ((Ptr Viewport) -> (IO (Ptr DrawWindow)))

foreign import ccall safe "gtk_viewport_get_view_window"
  gtk_viewport_get_view_window :: ((Ptr Viewport) -> (IO (Ptr DrawWindow)))