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
|
{-# OPTIONS_HADDOCK hide #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Container child Properties
--
-- Author : Duncan Coutts
--
-- Created: 16 April 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.
--
-- #hide
-- |
-- Maintainer : gtk2hs-users@lists.sourceforge.net
-- Stability : provisional
-- Portability : portable (depends on GHC)
--
-- Functions for getting and setting container child properties
--
module Graphics.UI.Gtk.Abstract.ContainerChildProperties (
containerChildGetPropertyBool,
containerChildSetPropertyBool,
newAttrFromContainerChildIntProperty,
newAttrFromContainerChildUIntProperty,
newAttrFromContainerChildBoolProperty,
newAttrFromContainerChildEnumProperty,
newAttrFromContainerChildFlagsProperty,
newAttrFromContainerChildStringProperty,
) where
import Control.Monad (liftM)
import System.Glib.FFI
import System.Glib.Flags
{#import Graphics.UI.Gtk.Types#}
import System.Glib.GType
import qualified System.Glib.GTypeConstants as GType
import System.Glib.GValueTypes
{#import System.Glib.GValue#} (GValue(GValue), allocaGValue, valueInit)
import System.Glib.Attributes (Attr, newAttr)
{# context lib="gtk" prefix="gtk" #}
containerChildSetPropertyInternal ::
(ContainerClass container, WidgetClass child)
=> GType
-> (GValue -> a -> IO ())
-> String
-> child
-> container
-> a
-> IO ()
containerChildSetPropertyInternal gtype valueSet prop child container val =
withCString prop $ \propertyNamePtr ->
allocaGValue $ \gvalue -> do
valueInit gvalue gtype
valueSet gvalue val
{# call container_child_set_property #}
(toContainer container)
(toWidget child)
propertyNamePtr
gvalue
containerChildGetPropertyInternal ::
(ContainerClass container, WidgetClass child)
=> GType
-> (GValue -> IO a)
-> String
-> child
-> container
-> IO a
containerChildGetPropertyInternal gtype valueGet prop child container =
withCString prop $ \propertyNamePtr ->
allocaGValue $ \gvalue -> do
valueInit gvalue gtype
{# call container_child_get_property #}
(toContainer container)
(toWidget child)
propertyNamePtr
gvalue
valueGet gvalue
-- Versions for specific types:
-- we actually don't use any others than bool at the moment
--
containerChildGetPropertyBool :: (ContainerClass container, WidgetClass child)
=> String -> child -> container -> IO Bool
containerChildGetPropertyBool =
containerChildGetPropertyInternal GType.bool valueGetBool
containerChildSetPropertyBool :: (ContainerClass container, WidgetClass child)
=> String -> child -> container -> Bool -> IO ()
containerChildSetPropertyBool =
containerChildSetPropertyInternal GType.bool valueSetBool
-- Convenience functions to make attribute implementations in the other modules
-- shorter and more easily extensible.
--
newAttrFromContainerChildIntProperty ::
(ContainerClass container, WidgetClass child)
=> String -> child -> Attr container Int
newAttrFromContainerChildIntProperty propName child = newAttr
(containerChildGetPropertyInternal GType.int valueGetInt propName child)
(containerChildSetPropertyInternal GType.int valueSetInt propName child)
newAttrFromContainerChildUIntProperty ::
(ContainerClass container, WidgetClass child)
=> String -> child -> Attr container Int
newAttrFromContainerChildUIntProperty propName child = newAttr
(containerChildGetPropertyInternal GType.uint
(\gv -> liftM fromIntegral $ valueGetUInt gv) propName child)
(containerChildSetPropertyInternal GType.uint
(\gv v -> valueSetUInt gv (fromIntegral v)) propName child)
newAttrFromContainerChildBoolProperty ::
(ContainerClass container, WidgetClass child)
=> String -> child -> Attr container Bool
newAttrFromContainerChildBoolProperty propName child = newAttr
(containerChildGetPropertyInternal GType.bool valueGetBool propName child)
(containerChildSetPropertyInternal GType.bool valueSetBool propName child)
newAttrFromContainerChildEnumProperty ::
(ContainerClass container, WidgetClass child, Enum enum)
=> String -> GType -> child -> Attr container enum
newAttrFromContainerChildEnumProperty propName gtype child = newAttr
(containerChildGetPropertyInternal gtype valueGetEnum propName child)
(containerChildSetPropertyInternal gtype valueSetEnum propName child)
newAttrFromContainerChildFlagsProperty ::
(ContainerClass container, WidgetClass child, Flags flag)
=> String -> GType -> child -> Attr container [flag]
newAttrFromContainerChildFlagsProperty propName gtype child = newAttr
(containerChildGetPropertyInternal gtype valueGetFlags propName child)
(containerChildSetPropertyInternal gtype valueSetFlags propName child)
newAttrFromContainerChildStringProperty ::
(ContainerClass container, WidgetClass child)
=> String -> child -> Attr container String
newAttrFromContainerChildStringProperty propName child = newAttr
(containerChildGetPropertyInternal GType.string valueGetString propName child)
(containerChildSetPropertyInternal GType.string valueSetString propName child)
|