1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
|
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Widget Layout
--
-- Author : Axel Simon
--
-- Created: 15 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.
--
-- |
-- Maintainer : gtk2hs-users@lists.sourceforge.net
-- Stability : provisional
-- Portability : portable (depends on GHC)
--
-- Infinite scrollable area containing child widgets and\/or custom drawing
--
module Graphics.UI.Gtk.Layout.Layout (
-- * Detail
--
-- | 'Layout' is similar to 'DrawingArea' in that it's a \"blank slate\" and
-- doesn't do anything but paint a blank background by default. It's different
-- in that it supports scrolling natively (you can add it to a
-- 'ScrolledWindow'), and it can contain child widgets, since it's a
-- 'Container'. However if you\'re just going to draw, a 'DrawingArea' is a
-- better choice since it has lower overhead.
-- * Class Hierarchy
-- |
-- @
-- | 'GObject'
-- | +----'Object'
-- | +----'Widget'
-- | +----'Container'
-- | +----Layout
-- @
-- * Types
Layout,
LayoutClass,
castToLayout, gTypeLayout,
toLayout,
-- * Constructors
layoutNew,
-- * Methods
layoutPut,
layoutMove,
layoutSetSize,
layoutGetSize,
layoutGetHAdjustment,
layoutGetVAdjustment,
layoutSetHAdjustment,
layoutSetVAdjustment,
layoutGetDrawWindow,
-- * Attributes
layoutHAdjustment,
layoutVAdjustment,
layoutWidth,
layoutHeight,
-- * Child Attributes
layoutChildX,
layoutChildY,
-- * Signals
onSetScrollAdjustments,
afterSetScrollAdjustments,
) where
import Data.Maybe (fromMaybe)
import Control.Monad (liftM)
import System.Glib.FFI
import System.Glib.Attributes
import System.Glib.Properties
import Graphics.UI.Gtk.Abstract.Object (makeNewObject)
{#import Graphics.UI.Gtk.Types#}
{#import Graphics.UI.Gtk.Signals#}
import Graphics.UI.Gtk.General.Structs (layoutGetDrawWindow)
import Graphics.UI.Gtk.Abstract.ContainerChildProperties
{# context lib="gtk" prefix="gtk" #}
--------------------
-- Constructors
-- | Creates a new 'Layout'. Unless you have a specific adjustment you'd like
-- the layout to use for scrolling, pass @Nothing@ for @hadjustment@ and
-- @vadjustment@.
--
layoutNew ::
Maybe Adjustment -- ^ @hadjustment@ - horizontal scroll adjustment, or
-- @Nothing@
-> Maybe Adjustment -- ^ @vadjustment@ - vertical scroll adjustment, or
-- @Nothing@
-> IO Layout
layoutNew hadjustment vadjustment =
makeNewObject mkLayout $
liftM (castPtr :: Ptr Widget -> Ptr Layout) $
{# call unsafe layout_new #}
(fromMaybe (Adjustment nullForeignPtr) hadjustment)
(fromMaybe (Adjustment nullForeignPtr) vadjustment)
--------------------
-- Methods
-- | Adds @childWidget@ to @layout@, at position @(x,y)@. @layout@ becomes
-- the new parent container of @childWidget@.
--
layoutPut :: (LayoutClass self, WidgetClass childWidget) => self
-> childWidget -- ^ @childWidget@ - child widget
-> Int -- ^ @x@ - X position of child widget
-> Int -- ^ @y@ - Y position of child widget
-> IO ()
layoutPut self childWidget x y =
{# call layout_put #}
(toLayout self)
(toWidget childWidget)
(fromIntegral x)
(fromIntegral y)
-- | Moves a current child of @layout@ to a new position.
--
layoutMove :: (LayoutClass self, WidgetClass childWidget) => self
-> childWidget -- ^ @childWidget@ - a current child of @layout@
-> Int -- ^ @x@ - X position to move to
-> Int -- ^ @y@ - Y position to move to
-> IO ()
layoutMove self childWidget x y =
{# call layout_move #}
(toLayout self)
(toWidget childWidget)
(fromIntegral x)
(fromIntegral y)
-- | Sets the size of the scrollable area of the layout.
--
layoutSetSize :: LayoutClass self => self
-> Int -- ^ @width@ - width of entire scrollable area
-> Int -- ^ @height@ - height of entire scrollable area
-> IO ()
layoutSetSize self width height =
{# call layout_set_size #}
(toLayout self)
(fromIntegral width)
(fromIntegral height)
-- | Gets the size that has been set on the layout, and that determines the
-- total extents of the layout's scrollbar area. See 'layoutSetSize'.
--
layoutGetSize :: LayoutClass self => self
-> IO (Int, Int) -- ^ @(width, height)@
layoutGetSize self =
alloca $ \widthPtr ->
alloca $ \heightPtr -> do
{# call unsafe layout_get_size #}
(toLayout self)
widthPtr
heightPtr
width <-peek widthPtr
height <- peek heightPtr
return (fromIntegral width, fromIntegral height)
-- | This function should only be called after the layout has been placed in a
-- 'ScrolledWindow' or otherwise configured for scrolling. It returns the
-- 'Adjustment' used for communication between the horizontal scrollbar and
-- @layout@.
--
-- See 'ScrolledWindow', 'Scrollbar', 'Adjustment' for details.
--
layoutGetHAdjustment :: LayoutClass self => self
-> IO Adjustment -- ^ returns horizontal scroll adjustment
layoutGetHAdjustment self =
makeNewObject mkAdjustment $
{# call unsafe layout_get_hadjustment #}
(toLayout self)
-- | This function should only be called after the layout has been placed in a
-- 'ScrolledWindow' or otherwise configured for scrolling. It returns the
-- 'Adjustment' used for communication between the vertical scrollbar and
-- @layout@.
--
-- See 'ScrolledWindow', 'Scrollbar', 'Adjustment' for details.
--
layoutGetVAdjustment :: LayoutClass self => self
-> IO Adjustment -- ^ returns vertical scroll adjustment
layoutGetVAdjustment self =
makeNewObject mkAdjustment $
{# call unsafe layout_get_vadjustment #}
(toLayout self)
-- | Sets the horizontal scroll adjustment for the layout.
--
-- See 'ScrolledWindow', 'Scrollbar', 'Adjustment' for details.
--
layoutSetHAdjustment :: LayoutClass self => self
-> Adjustment -- ^ @adjustment@ - new scroll adjustment
-> IO ()
layoutSetHAdjustment self adjustment =
{# call layout_set_hadjustment #}
(toLayout self)
adjustment
-- | Sets the vertical scroll adjustment for the layout.
--
-- See 'ScrolledWindow', 'Scrollbar', 'Adjustment' for details.
--
layoutSetVAdjustment :: LayoutClass self => self
-> Adjustment -- ^ @adjustment@ - new scroll adjustment
-> IO ()
layoutSetVAdjustment self adjustment =
{# call layout_set_vadjustment #}
(toLayout self)
adjustment
--------------------
-- Attributes
-- | The 'Adjustment' for the horizontal position.
--
layoutHAdjustment :: LayoutClass self => Attr self Adjustment
layoutHAdjustment = newAttr
layoutGetHAdjustment
layoutSetHAdjustment
-- | The 'Adjustment' for the vertical position.
--
layoutVAdjustment :: LayoutClass self => Attr self Adjustment
layoutVAdjustment = newAttr
layoutGetVAdjustment
layoutSetVAdjustment
-- | The width of the layout.
--
-- Allowed values: \<= @('maxBound' :: Int)@
--
-- Default value: 100
--
layoutWidth :: LayoutClass self => Attr self Int
layoutWidth = newAttrFromUIntProperty "width"
-- | The height of the layout.
--
-- Allowed values: \<= @('maxBound' :: Int)@
--
-- Default value: 100
--
layoutHeight :: LayoutClass self => Attr self Int
layoutHeight = newAttrFromUIntProperty "height"
--------------------
-- Child Attributes
-- | X position of child widget.
--
-- Default value: 0
--
layoutChildX :: (LayoutClass self, WidgetClass child) => child -> Attr self Int
layoutChildX = newAttrFromContainerChildIntProperty "x"
-- | Y position of child widget.
--
-- Default value: 0
--
layoutChildY :: (LayoutClass self, WidgetClass child) => child -> Attr self Int
layoutChildY = newAttrFromContainerChildIntProperty "y"
--------------------
-- Signals
-- | In case the adjustments are replaced, this signal is emitted.
--
onSetScrollAdjustments, afterSetScrollAdjustments :: LayoutClass self => self
-> (Adjustment -> Adjustment -> IO ())
-> IO (ConnectId self)
onSetScrollAdjustments = connect_OBJECT_OBJECT__NONE "set-scroll-adjustments" False
afterSetScrollAdjustments = connect_OBJECT_OBJECT__NONE "set-scroll-adjustments" True
|