File: ImageMenuItem.chs

package info (click to toggle)
haskell-gtk 0.11.0-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,920 kB
  • ctags: 82
  • sloc: haskell: 1,929; ansic: 714; sh: 5; makefile: 3
file content (170 lines) | stat: -rw-r--r-- 5,151 bytes parent folder | download
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
-- -*-haskell-*-
--  GIMP Toolkit (GTK) Widget ImageMenuItem
--
--  Author : Jonas Svensson
--
--  Created: 12 Aug 2002
--
--  Copyright (C) 2002 Jonas Svensson
--
--  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.
--
-- TODO
--
-- imageMenuItemNewFromSock should also have a AccelGroup argument
--
-- |
-- Maintainer  : gtk2hs-users@lists.sourceforge.net
-- Stability   : provisional
-- Portability : portable (depends on GHC)
--
-- A menu item with an icon
--
module Graphics.UI.Gtk.MenuComboToolbar.ImageMenuItem (
-- * Detail
-- 
-- | A 'ImageMenuItem' is a menu item which has an icon next to the text
-- label.
--
-- Note that the user can disable display of menu icons, so make sure to
-- still fill in the text label.

-- * Class Hierarchy
-- |
-- @
-- |  'GObject'
-- |   +----'Object'
-- |         +----'Widget'
-- |               +----'Container'
-- |                     +----'Bin'
-- |                           +----'Item'
-- |                                 +----'MenuItem'
-- |                                       +----ImageMenuItem
-- @

-- * Types
  ImageMenuItem,
  ImageMenuItemClass,
  castToImageMenuItem, gTypeImageMenuItem,
  toImageMenuItem,

-- * Constructors
  imageMenuItemNew,
  imageMenuItemNewFromStock,
  imageMenuItemNewWithLabel,
  imageMenuItemNewWithMnemonic,

-- * Methods
  imageMenuItemSetImage,
  imageMenuItemGetImage,

-- * Attributes
  imageMenuItemImage,
  ) where

import Control.Monad	(liftM)

import System.Glib.FFI
import System.Glib.UTFString
import System.Glib.Attributes
import Graphics.UI.Gtk.Abstract.Object	(makeNewObject)
{#import Graphics.UI.Gtk.Types#}
import Graphics.UI.Gtk.General.StockItems

{# context lib="gtk" prefix="gtk" #}

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

-- | Creates a new 'ImageMenuItem' with an empty label.
--
imageMenuItemNew :: IO ImageMenuItem
imageMenuItemNew =
  makeNewObject mkImageMenuItem $
  liftM (castPtr :: Ptr Widget -> Ptr ImageMenuItem) $
  {# call unsafe image_menu_item_new #}

-- | Creates a new 'ImageMenuItem' containing the image and text from a stock
-- item.
--
imageMenuItemNewFromStock :: 
    StockId          -- ^ @stockId@ - the name of the stock item.
 -> IO ImageMenuItem
imageMenuItemNewFromStock stockId =
  makeNewObject mkImageMenuItem $
  liftM (castPtr :: Ptr Widget -> Ptr ImageMenuItem) $
  withUTFString stockId $ \stockIdPtr ->
  {# call unsafe image_menu_item_new_from_stock #}
    stockIdPtr
    (AccelGroup nullForeignPtr)

-- | Creates a new 'ImageMenuItem' containing a label.
--
imageMenuItemNewWithLabel :: 
    String           -- ^ @label@ - the text of the menu item.
 -> IO ImageMenuItem
imageMenuItemNewWithLabel label =
  makeNewObject mkImageMenuItem $
  liftM (castPtr :: Ptr Widget -> Ptr ImageMenuItem) $
  withUTFString label $ \labelPtr ->
  {# call unsafe image_menu_item_new_with_label #}
    labelPtr

-- | Creates a new 'ImageMenuItem' containing a label. The label will be
-- created using 'Graphics.UI.Gtk.Display.Label.labelNewWithMnemonic', so
-- underscores in @label@ indicate the mnemonic for the menu item.
--
imageMenuItemNewWithMnemonic :: 
    String           -- ^ @label@ - the text of the menu item, with an
                     -- underscore in front of the mnemonic character
 -> IO ImageMenuItem
imageMenuItemNewWithMnemonic label =
  makeNewObject mkImageMenuItem $
  liftM (castPtr :: Ptr Widget -> Ptr ImageMenuItem) $
  withUTFString label $ \labelPtr ->
  {# call unsafe image_menu_item_new_with_mnemonic #}
    labelPtr

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

-- | Sets the image of the image menu item to the given widget. Note that it
-- depends on the \"show-menu-images\" setting whether the image will be
-- displayed or not.
--
imageMenuItemSetImage :: (ImageMenuItemClass self, WidgetClass image) => self
 -> image -- ^ @image@ - a widget to set as the image for the menu item.
 -> IO ()
imageMenuItemSetImage self image =
  {# call unsafe image_menu_item_set_image #}
    (toImageMenuItem self)
    (toWidget image)

-- | Gets the widget that is currently set as the image.
-- See 'imageMenuItemSetImage'.
--
imageMenuItemGetImage :: ImageMenuItemClass self => self
 -> IO (Maybe Widget) -- ^ returns the widget set as image of or @Nothing@ if
                      -- none has been set.
imageMenuItemGetImage self =
  maybeNull (makeNewObject mkWidget) $
  {# call unsafe image_menu_item_get_image #}
    (toImageMenuItem self)

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

-- | Child widget to appear next to the menu text.
--
imageMenuItemImage :: (ImageMenuItemClass self, WidgetClass image) => ReadWriteAttr self (Maybe Widget) image
imageMenuItemImage = newAttr
  imageMenuItemGetImage
  imageMenuItemSetImage