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
|
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Widget Frame
--
-- 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)
--
-- A bin with a decorative frame and optional label
--
module Graphics.UI.Gtk.Ornaments.Frame (
-- * Detail
--
-- | The frame widget is a Bin that surrounds its child with a decorative
-- frame and an optional label. If present, the label is drawn in a gap in the
-- top side of the frame. The position of the label can be controlled with
-- 'frameSetLabelAlign'.
-- * Class Hierarchy
-- |
-- @
-- | 'GObject'
-- | +----'Object'
-- | +----'Widget'
-- | +----'Container'
-- | +----'Bin'
-- | +----Frame
-- | +----'AspectFrame'
-- @
-- * Types
Frame,
FrameClass,
castToFrame, gTypeFrame,
toFrame,
-- * Constructors
frameNew,
-- * Methods
frameSetLabel,
frameGetLabel,
frameSetLabelWidget,
frameGetLabelWidget,
frameSetLabelAlign,
frameGetLabelAlign,
ShadowType(..),
frameSetShadowType,
frameGetShadowType,
-- * Attributes
frameLabel,
frameLabelXAlign,
frameLabelYAlign,
frameShadowType,
frameLabelWidget,
) where
import Control.Monad (liftM)
import System.Glib.FFI
import System.Glib.UTFString
import System.Glib.Attributes
import System.Glib.Properties
import Graphics.UI.Gtk.Abstract.Object (makeNewObject)
{#import Graphics.UI.Gtk.Types#}
import Graphics.UI.Gtk.General.Enums (ShadowType(..))
{# context lib="gtk" prefix="gtk" #}
--------------------
-- Constructors
-- | Creates a new 'Frame' without a label.
--
-- * A label can later be set by calling 'frameSetLabel'.
--
frameNew :: IO Frame
frameNew =
makeNewObject mkFrame $
liftM (castPtr :: Ptr Widget -> Ptr Frame) $
{# call unsafe frame_new #}
nullPtr
--------------------
-- Methods
-- | Sets the text of the label.
--
frameSetLabel :: FrameClass self => self
-> String -- ^ @label@ - the text to use as the label of the frame
-> IO ()
frameSetLabel self label =
withUTFString label $ \labelPtr ->
{# call frame_set_label #}
(toFrame self)
labelPtr
-- | Sets the label widget for the frame. This is the widget that will appear
-- embedded in the top edge of the frame as a title.
--
frameSetLabelWidget :: (FrameClass self, WidgetClass labelWidget) => self
-> labelWidget
-> IO ()
frameSetLabelWidget self labelWidget =
{# call frame_set_label_widget #}
(toFrame self)
(toWidget labelWidget)
-- | Retrieves the label widget for the frame. See 'frameSetLabelWidget'.
--
frameGetLabelWidget :: FrameClass self => self
-> IO (Maybe Widget) -- ^ returns the label widget, or @Nothing@ if there is
-- none.
frameGetLabelWidget self =
maybeNull (makeNewObject mkWidget) $
{# call frame_get_label_widget #}
(toFrame self)
-- | Sets the alignment of the frame widget's label. The default values for a
-- newly created frame are 0.0 and 0.5.
--
frameSetLabelAlign :: FrameClass self => self
-> Float -- ^ @xalign@ - The position of the label along the top edge of the
-- widget. A value of 0.0 represents left alignment; 1.0 represents
-- right alignment.
-> Float -- ^ @yalign@ - The y alignment of the label. A value of 0.0 aligns
-- under the frame; 1.0 aligns above the frame.
-> IO ()
frameSetLabelAlign self xalign yalign =
{# call frame_set_label_align #}
(toFrame self)
(realToFrac xalign)
(realToFrac yalign)
-- | Retrieves the X and Y alignment of the frame's label. See
-- 'frameSetLabelAlign'.
--
frameGetLabelAlign :: FrameClass self => self
-> IO (Float, Float) -- ^ @(xalign, yalign)@
frameGetLabelAlign self =
alloca $ \xalignPtr ->
alloca $ \yalignPtr -> do
{# call unsafe frame_get_label_align #}
(toFrame self)
xalignPtr
yalignPtr
xalign <- peek xalignPtr
yalign <- peek yalignPtr
return (realToFrac xalign, realToFrac yalign)
-- | Sets the shadow type of the frame.
--
frameSetShadowType :: FrameClass self => self -> ShadowType -> IO ()
frameSetShadowType self type_ =
{# call frame_set_shadow_type #}
(toFrame self)
((fromIntegral . fromEnum) type_)
-- | Retrieves the shadow type of the frame. See 'frameSetShadowType'.
--
frameGetShadowType :: FrameClass self => self -> IO ShadowType
frameGetShadowType self =
liftM (toEnum . fromIntegral) $
{# call unsafe frame_get_shadow_type #}
(toFrame self)
-- | If the frame's label widget is a 'Label', returns the text in the label
-- widget.
--
frameGetLabel :: FrameClass self => self
-> IO String -- ^ returns the text in the label, or if there was no label
-- widget or the lable widget was not a 'Label' then an
-- exception is thrown
frameGetLabel self =
throwIfNull "frameGetLabel: the title of the frame was not a Label widget."
({# call unsafe frame_get_label #}
(toFrame self))
>>= peekUTFString
--------------------
-- Attributes
-- | Text of the frame's label.
--
frameLabel :: FrameClass self => Attr self String
frameLabel = newAttr
frameGetLabel
frameSetLabel
-- | The horizontal alignment of the label.
--
-- Allowed values: [0,1]
--
-- Default value: 0.5
--
frameLabelXAlign :: FrameClass self => Attr self Float
frameLabelXAlign = newAttrFromFloatProperty "label-xalign"
-- | The vertical alignment of the label.
--
-- Allowed values: [0,1]
--
-- Default value: 0.5
--
frameLabelYAlign :: FrameClass self => Attr self Float
frameLabelYAlign = newAttrFromFloatProperty "label-yalign"
-- | Appearance of the frame border.
--
-- Default value: 'ShadowEtchedIn'
--
frameShadowType :: FrameClass self => Attr self ShadowType
frameShadowType = newAttr
frameGetShadowType
frameSetShadowType
-- | A widget to display in place of the usual frame label.
--
frameLabelWidget :: (FrameClass self, WidgetClass labelWidget) => ReadWriteAttr self (Maybe Widget) labelWidget
frameLabelWidget = newAttr
frameGetLabelWidget
frameSetLabelWidget
|