~ubuntu-branches/ubuntu/lucid/gtk2hs/lucid

« back to all changes in this revision

Viewing changes to gtk/Graphics/UI/Gtk/MenuComboToolbar/RadioToolButton.chs.pp

  • Committer: Bazaar Package Importer
  • Author(s): Liyang HU
  • Date: 2006-07-22 21:31:58 UTC
  • Revision ID: james.westby@ubuntu.com-20060722213158-he81wo6uam30m9aw
Tags: upstream-0.9.10
ImportĀ upstreamĀ versionĀ 0.9.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-- -*-haskell-*-
 
2
--  GIMP Toolkit (GTK) Widget RadioToolButton
 
3
--
 
4
--  Author : Duncan Coutts
 
5
--
 
6
--  Created: 7 April 2005
 
7
--
 
8
--  Version $Revision: 1.4 $ from $Date: 2005/10/19 12:57:37 $
 
9
--
 
10
--  Copyright (C) 2005 Duncan Coutts
 
11
--
 
12
--  This library is free software; you can redistribute it and/or
 
13
--  modify it under the terms of the GNU Lesser General Public
 
14
--  License as published by the Free Software Foundation; either
 
15
--  version 2.1 of the License, or (at your option) any later version.
 
16
--
 
17
--  This library is distributed in the hope that it will be useful,
 
18
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
20
--  Lesser General Public License for more details.
 
21
--
 
22
-- |
 
23
-- Maintainer  : gtk2hs-users@lists.sourceforge.net
 
24
-- Stability   : provisional
 
25
-- Portability : portable (depends on GHC)
 
26
--
 
27
-- A toolbar item that contains a radio button
 
28
--
 
29
-- * Module available since Gtk+ version 2.4
 
30
--
 
31
module Graphics.UI.Gtk.MenuComboToolbar.RadioToolButton (
 
32
-- * Detail
 
33
-- 
 
34
-- | A 'RadioToolButton' is a 'ToolItem' that contains a radio button, that
 
35
-- is, a button that is part of a group of toggle buttons where only one button
 
36
-- can be active at a time.
 
37
--
 
38
-- Use 'radioToolButtonNew' to create a new 'RadioToolButton'. use
 
39
-- 'radioToolButtonNewFromWidget' to create a new 'RadioToolButton' that is
 
40
-- part of the same group as an existing 'RadioToolButton'. Use
 
41
-- 'radioToolButtonNewFromStock' or 'radioToolButtonNewFromWidgetWithStock' to
 
42
-- create a new 'RadioToolButton' containing a stock item.
 
43
 
 
44
-- * Class Hierarchy
 
45
-- |
 
46
-- @
 
47
-- |  'GObject'
 
48
-- |   +----'Object'
 
49
-- |         +----'Widget'
 
50
-- |               +----'Container'
 
51
-- |                     +----'Bin'
 
52
-- |                           +----'ToolItem'
 
53
-- |                                 +----'ToolButton'
 
54
-- |                                       +----'ToggleToolButton'
 
55
-- |                                             +----RadioToolButton
 
56
-- @
 
57
 
 
58
#if GTK_CHECK_VERSION(2,4,0)
 
59
-- * Types
 
60
  RadioToolButton,
 
61
  RadioToolButtonClass,
 
62
  castToRadioToolButton,
 
63
  toRadioToolButton,
 
64
 
 
65
-- * Constructors
 
66
  radioToolButtonNew,
 
67
  radioToolButtonNewFromStock,
 
68
  radioToolButtonNewFromWidget,
 
69
  radioToolButtonNewWithStockFromWidget,
 
70
 
 
71
-- * Methods
 
72
  radioToolButtonGetGroup,
 
73
  radioToolButtonSetGroup,
 
74
 
 
75
-- * Attributes
 
76
  radioToolButtonGroup,
 
77
#endif
 
78
  ) where
 
79
 
 
80
import Monad    (liftM)
 
81
 
 
82
import System.Glib.FFI
 
83
import System.Glib.UTFString
 
84
import System.Glib.GList
 
85
import System.Glib.Attributes
 
86
import Graphics.UI.Gtk.Abstract.Object  (makeNewObject)
 
87
{#import Graphics.UI.Gtk.Types#}
 
88
{#import Graphics.UI.Gtk.Signals#}
 
89
 
 
90
{# context lib="gtk" prefix="gtk" #}
 
91
 
 
92
#if GTK_CHECK_VERSION(2,4,0)
 
93
--------------------
 
94
-- Constructors
 
95
 
 
96
-- | Creates a new 'RadioToolButton', creating a new group.
 
97
--
 
98
radioToolButtonNew :: IO RadioToolButton
 
99
radioToolButtonNew =
 
100
  makeNewObject mkRadioToolButton $
 
101
  liftM (castPtr :: Ptr ToolItem -> Ptr RadioToolButton) $
 
102
  {# call gtk_radio_tool_button_new #}
 
103
    nullPtr
 
104
 
 
105
-- | Creates a new 'RadioToolButton', creating a new group. The new
 
106
-- 'RadioToolButton' will contain an icon and label from the stock item
 
107
-- indicated by @stockId@.
 
108
--
 
109
radioToolButtonNewFromStock :: 
 
110
    String             -- ^ @stockId@ - the name of a stock item
 
111
 -> IO RadioToolButton
 
112
radioToolButtonNewFromStock stockId =
 
113
  makeNewObject mkRadioToolButton $
 
114
  liftM (castPtr :: Ptr ToolItem -> Ptr RadioToolButton) $
 
115
  withUTFString stockId $ \stockIdPtr ->
 
116
  {# call gtk_radio_tool_button_new_from_stock #}
 
117
    nullPtr
 
118
    stockIdPtr
 
119
 
 
120
-- | Creates a new 'RadioToolButton' adding it to the same group as 
 
121
-- the group to which @groupMember@ belongs.
 
122
--
 
123
radioToolButtonNewFromWidget :: RadioToolButtonClass groupMember => 
 
124
    groupMember        -- ^ @groupMember@ - a member of an existing radio group,
 
125
                       -- to which the new radio tool button will be added.
 
126
 -> IO RadioToolButton
 
127
radioToolButtonNewFromWidget group =
 
128
  makeNewObject mkRadioToolButton $
 
129
  liftM (castPtr :: Ptr ToolItem -> Ptr RadioToolButton) $
 
130
  {# call gtk_radio_tool_button_new_from_widget #}
 
131
    (toRadioToolButton group)
 
132
 
 
133
-- | Creates a new 'RadioToolButton' adding it to the same group as the group
 
134
-- to which @groupMember@ belongs. The new 'RadioToolButton' will contain an
 
135
-- icon and label from the stock item indicated by @stockId@.
 
136
--
 
137
radioToolButtonNewWithStockFromWidget :: RadioToolButtonClass groupMember => 
 
138
    groupMember        -- ^ @groupMember@ - a member of an existing radio group,
 
139
                       -- to which the new radio tool button will be added.
 
140
 -> String             -- ^ @stockId@ - the name of a stock item
 
141
 -> IO RadioToolButton
 
142
radioToolButtonNewWithStockFromWidget group stockId =
 
143
  makeNewObject mkRadioToolButton $
 
144
  liftM (castPtr :: Ptr ToolItem -> Ptr RadioToolButton) $
 
145
  withUTFString stockId $ \stockIdPtr ->
 
146
  {# call gtk_radio_tool_button_new_with_stock_from_widget #}
 
147
    (toRadioToolButton group)
 
148
    stockIdPtr
 
149
 
 
150
--------------------
 
151
-- Methods
 
152
 
 
153
-- | Returns the radio button group @button@ belongs to.
 
154
--
 
155
radioToolButtonGetGroup :: RadioToolButtonClass self => self
 
156
 -> IO [RadioToolButton] -- ^ returns the group the button belongs to.
 
157
radioToolButtonGetGroup self =
 
158
  {# call unsafe gtk_radio_tool_button_get_group #}
 
159
    (toRadioToolButton self)
 
160
  >>= readGSList
 
161
  >>= mapM (\elemPtr -> makeNewObject mkRadioToolButton (return elemPtr))
 
162
 
 
163
-- | Adds @button@ to @group@, removing it from the group it belonged to
 
164
-- before.
 
165
--
 
166
radioToolButtonSetGroup :: RadioToolButtonClass self => self
 
167
 -> RadioToolButton -- ^ @groupMember@ - a member of an existing radio group,
 
168
                    -- to which the radio tool button will be added.
 
169
 -> IO ()
 
170
radioToolButtonSetGroup self group =
 
171
  {# call unsafe gtk_radio_tool_button_get_group #} group >>= \groupGSList ->
 
172
  {# call gtk_radio_tool_button_set_group #}
 
173
    (toRadioToolButton self)
 
174
    groupGSList
 
175
 
 
176
--------------------
 
177
-- Properties
 
178
 
 
179
-- | Sets a new group for a radio tool button.
 
180
--
 
181
radioToolButtonGroup :: RadioToolButtonClass self => ReadWriteAttr self [RadioToolButton] RadioToolButton
 
182
radioToolButtonGroup = newAttr
 
183
  radioToolButtonGetGroup
 
184
  radioToolButtonSetGroup
 
185
#endif