File: InfoBar.chs

package info (click to toggle)
haskell-gtk 0.15.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,964 kB
  • sloc: haskell: 3,346; ansic: 826; makefile: 161
file content (272 lines) | stat: -rw-r--r-- 8,218 bytes parent folder | download | duplicates (9)
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
{-# LANGUAGE CPP #-}
-- -*-haskell-*-
--  GIMP Toolkit (GTK) Widget InfoBar
--
--  Author : Andy Stewart
--
--  Created: 27 Mar 2010
--
--  Copyright (C) 2010 Andy Stewart
--
--  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.
--
-- The following varargs functions can't bound:
--
--   gtk_info_bar_new_with_buttons
--   gtk_info_bar_add_buttons
--
-- Use 'infoBarAddButton' replace.
--
-- |
-- Maintainer  : gtk2hs-users@lists.sourceforge.net
-- Stability   : provisional
-- Portability : portable (depends on GHC)
--
-- Report important messages to the user
--
module Graphics.UI.Gtk.Display.InfoBar (

-- * Detail
--
-- | 'InfoBar' is a widget that can be used to show messages to the user
-- without showing a dialog. It is often temporarily shown at the top or bottom
-- of a document. In contrast to 'Dialog', which has a horizontal action area
-- at the bottom, 'InfoBar' has a vertical action area at the side.
--
-- The API of 'InfoBar' is very similar to 'Dialog', allowing you to add
-- buttons to the action area with 'infoBarAddButton'.
-- The sensitivity of action widgets can be controlled
-- with 'infoBarSetResponseSensitive'. To add widgets to the main content area
-- of a 'InfoBar', use 'infoBarGetContentArea' and add your widgets to the
-- container.
--
-- Similar to 'MessageDialog', the contents of a 'InfoBar' can by classified
-- as error message, warning, informational message, etc, by using
-- 'infoBarSetMessageType'. Gtk+ uses the message type to determine the
-- background color of the message area.

-- * Class Hierarchy
--
-- |
-- @
-- |  'GObject'
-- |   +----'Object'
-- |         +----'Widget'
-- |               +----'Container'
-- |                     +----'Box'
-- |                           +----'HBox'
-- |                                 +----InfoBar
-- @

#if GTK_CHECK_VERSION(2,18,0)
-- * Types
  InfoBar,
  InfoBarClass,
  castToInfoBar,
  toInfoBar,

-- * Constructors
  infoBarNew,

-- * Methods
  infoBarAddActionWidget,
  infoBarAddButton,
  infoBarSetResponseSensitive,
  infoBarSetDefaultResponse,
  infoBarEmitResponse,
  infoBarGetActionArea,
  infoBarGetContentArea,

-- * Attributes
  infoBarMessageType,

-- * Signals
  infoBarResponse,
  infoBarClose,
#endif
  ) 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.Windows.MessageDialog#} (MessageType)
{#import Graphics.UI.Gtk.Types#}
{#import Graphics.UI.Gtk.Signals#}

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

--------------------
-- Interfaces

-- instance BuildableClass InfoBar

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

#if GTK_CHECK_VERSION(2,18,0)
-- | Creates a new 'InfoBar' object.
--
-- * Available since Gtk+ version 2.18
--
infoBarNew :: IO InfoBar
infoBarNew =
  makeNewObject mkInfoBar $
  liftM (castPtr :: Ptr Widget -> Ptr InfoBar) $
  {# call gtk_info_bar_new #}

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

-- | Add an activatable widget to the action area of a 'InfoBar', connecting a signal handler that will
-- emit the "response" signal on the message area when the widget is activated. The widget is appended
-- to the end of the message areas action area.
--
-- * Available since Gtk+ version 2.18
--
infoBarAddActionWidget :: (InfoBarClass self, WidgetClass child) => self
 -> child -- ^ @child@ - an activatable widget
 -> Int   -- ^ @responseId@ - response ID for @child@
 -> IO ()
infoBarAddActionWidget self child responseId =
  {# call gtk_info_bar_add_action_widget #}
    (toInfoBar self)
    (toWidget child)
    (fromIntegral responseId)

-- | Adds a button with the given text (or a stock button, if buttonText is a
-- stock ID) and sets things up so that clicking the button will emit the
-- \"response\" signal with the given responseId. The button is appended to
-- the end of the info bars's action area. The button widget is returned, but
-- usually you don't need it.
--
-- * Available since Gtk+ version 2.18
--
infoBarAddButton :: (InfoBarClass self, GlibString string) => self
 -> string    -- ^ @buttonText@ - text of button, or stock ID
 -> Int       -- ^ @responseId@ - response ID for the button
 -> IO Button -- ^ returns the button widget that was added
infoBarAddButton self buttonText responseId =
  makeNewObject mkButton $
  withUTFString buttonText $ \buttonTextPtr ->
  liftM (castPtr :: Ptr Widget -> Ptr Button) $
     {# call gtk_info_bar_add_button #}
       (toInfoBar self)
       buttonTextPtr
       (fromIntegral responseId)

-- | Calls 'widgetSetSensitive' for each widget in the
-- info bars's action area with the given responseId. A convenient way to
-- sensitize\/desensitize dialog buttons.
--
-- * Available since Gtk+ version 2.18
--
infoBarSetResponseSensitive :: InfoBarClass self => self
 -> Int  -- ^ @responseId@ - a response ID
 -> Bool -- ^ @setting@ - @True@ for sensitive
 -> IO ()
infoBarSetResponseSensitive self responseId setting =
  {# call gtk_info_bar_set_response_sensitive #}
    (toInfoBar self)
    (fromIntegral responseId)
    (fromBool setting)

-- | Sets the last widget in the info bar's action area with the given
-- responseId as the default widget for the dialog. Pressing \"Enter\"
-- normally activates the default widget.
--
-- * Available since Gtk+ version 2.18
--
infoBarSetDefaultResponse :: InfoBarClass self => self
 -> Int -- ^ @responseId@ - a response ID
 -> IO ()
infoBarSetDefaultResponse self responseId =
  {# call gtk_info_bar_set_default_response #}
    (toInfoBar self)
    (fromIntegral responseId)

-- | Emits the \'response\' signal with the given @responseId@.
--
-- * Available since Gtk+ version 2.18
--
infoBarEmitResponse :: InfoBarClass self => self
 -> Int -- ^ @responseId@ - a response ID
 -> IO ()
infoBarEmitResponse self responseId =
  {# call gtk_info_bar_response #}
    (toInfoBar self)
    (fromIntegral responseId)

-- | Returns the action area of @infoBar@.
--
-- * Available since Gtk+ version 2.18
--
infoBarGetActionArea :: InfoBarClass self => self
 -> IO Widget -- ^ returns the action area.
infoBarGetActionArea self =
  makeNewObject mkWidget $
  {# call gtk_info_bar_get_action_area #}
    (toInfoBar self)

-- | Returns the content area of @infoBar@.
--
-- * Available since Gtk+ version 2.18
--
infoBarGetContentArea :: InfoBarClass self => self
 -> IO Widget -- ^ returns the content area.
infoBarGetContentArea self =
  makeNewObject mkWidget $
  {# call gtk_info_bar_get_content_area #}
    (toInfoBar self)

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

-- | The type of the message.
--
-- The type is used to determine the colors to use in the info bar.
--
-- If the type is 'MessageOther', no info bar is painted but the colors are still set.
--
-- Default value: 'MessageInfo'
--
-- * Available since Gtk+ version 2.18
--
infoBarMessageType :: InfoBarClass self => Attr self MessageType
infoBarMessageType = newAttrFromEnumProperty "message-type"
                       {# call pure unsafe gtk_message_type_get_type #}

--------------------
-- Signals

-- | The 'close' signal is a keybinding signal which gets emitted when the user uses a keybinding to
-- dismiss the info bar.
--
-- The default binding for this signal is the Escape key.
--
-- Since 2.18
infoBarClose :: InfoBarClass self => Signal self (IO ())
infoBarClose = Signal (connect_NONE__NONE "close")


-- | Emitted when an action widget is clicked or the application programmer
-- calls 'dialogResponse'. The @responseId@ depends on which action widget was
-- clicked.
--
-- * Available since Gtk+ version 2.18
--
infoBarResponse :: InfoBarClass self => Signal self (Int -> IO ())
infoBarResponse = Signal (connect_INT__NONE "response")
#endif