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

« back to all changes in this revision

Viewing changes to gtk/Graphics/UI/Gtk/Misc/Tooltips.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 Tooltips
 
3
--
 
4
--  Author : Axel Simon
 
5
--
 
6
--  Created: 23 May 2001
 
7
--
 
8
--  Version $Revision: 1.6 $ from $Date: 2005/10/19 12:57:37 $
 
9
--
 
10
--  Copyright (C) 1999-2005 Axel Simon
 
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
-- Add tips to your widgets
 
28
--
 
29
module Graphics.UI.Gtk.Misc.Tooltips (
 
30
-- * Detail
 
31
-- 
 
32
-- | Tooltips are the messages that appear next to a widget when the mouse
 
33
-- pointer is held over it for a short amount of time. They are especially
 
34
-- helpful for adding more verbose descriptions of things such as buttons in a
 
35
-- toolbar.
 
36
--
 
37
-- An individual tooltip belongs to a group of tooltips. A group is created
 
38
-- with a call to 'tooltipsNew'. Every tooltip in the group can then be turned
 
39
-- off with a call to 'tooltipsDisable' and enabled with 'tooltipsEnable'.
 
40
--
 
41
#ifndef DISABLE_DEPRECATED
 
42
-- The length of time the user must keep the mouse over a widget before the
 
43
-- tip is shown, can be altered with 'tooltipsSetDelay'. This is set on a \'per
 
44
-- group of tooltips\' basis.
 
45
--
 
46
#endif
 
47
-- To assign a tip to a particular 'Widget', 'tooltipsSetTip' is used.
 
48
--
 
49
-- To associate 'Tooltips' to a widget it is has to have its own 'DrawWindow'.
 
50
-- Otherwise the widget must be set into an 'EventBox'.
 
51
--
 
52
-- The default appearance of all tooltips in a program is determined by the
 
53
-- current Gtk+ theme that the user has selected.
 
54
--
 
55
-- Information about the tooltip (if any) associated with an arbitrary
 
56
-- widget can be retrieved using 'tooltipsDataGet'.
 
57
 
 
58
-- * Class Hierarchy
 
59
-- |
 
60
-- @
 
61
-- |  'GObject'
 
62
-- |   +----'Object'
 
63
-- |         +----Tooltips
 
64
-- @
 
65
 
 
66
-- * Types
 
67
  Tooltips,
 
68
  TooltipsClass,
 
69
  castToTooltips,
 
70
  toTooltips,
 
71
 
 
72
-- * Constructors
 
73
  tooltipsNew,
 
74
 
 
75
-- * Methods
 
76
  tooltipsEnable,
 
77
  tooltipsDisable,
 
78
#ifndef DISABLE_DEPRECATED
 
79
  tooltipsSetDelay,
 
80
#endif
 
81
  tooltipsSetTip,
 
82
  tooltipsDataGet
 
83
  ) where
 
84
 
 
85
import Monad    (liftM)
 
86
 
 
87
import System.Glib.FFI
 
88
import System.Glib.UTFString
 
89
import Graphics.UI.Gtk.Abstract.Object  (makeNewObject)
 
90
{#import Graphics.UI.Gtk.Types#}
 
91
{#import Graphics.UI.Gtk.Signals#}
 
92
 
 
93
{# context lib="gtk" prefix="gtk" #}
 
94
 
 
95
--------------------
 
96
-- Constructors
 
97
 
 
98
-- | Create a new goup of 'Tooltips'.
 
99
--
 
100
tooltipsNew :: IO Tooltips
 
101
tooltipsNew =
 
102
  makeNewObject mkTooltips $
 
103
  {# call unsafe tooltips_new #}
 
104
 
 
105
--------------------
 
106
-- Methods
 
107
 
 
108
-- | Allows the user to see your tooltips as they navigate your application.
 
109
--
 
110
tooltipsEnable :: TooltipsClass self => self -> IO ()
 
111
tooltipsEnable self =
 
112
  {# call unsafe tooltips_enable #}
 
113
    (toTooltips self)
 
114
 
 
115
-- | Causes all tooltips in @tooltips@ to become inactive. Any widgets that
 
116
-- have tips associated with that group will no longer display their tips until
 
117
-- they are enabled again with 'tooltipsEnable'.
 
118
--
 
119
tooltipsDisable :: TooltipsClass self => self -> IO ()
 
120
tooltipsDisable self =
 
121
  {# call unsafe tooltips_disable #}
 
122
    (toTooltips self)
 
123
 
 
124
#ifndef DISABLE_DEPRECATED
 
125
-- | Sets the time between the user moving the mouse over a widget and the
 
126
-- widget's tooltip appearing.
 
127
--
 
128
-- * Warning: this function is deprecated and should not be used in
 
129
-- newly-written code.
 
130
--
 
131
tooltipsSetDelay :: TooltipsClass self => self
 
132
 -> Int   -- ^ @delay@ - the delay in milliseconds
 
133
 -> IO ()
 
134
tooltipsSetDelay self delay =
 
135
  {# call unsafe tooltips_set_delay #}
 
136
    (toTooltips self)
 
137
    (fromIntegral delay)
 
138
#endif
 
139
 
 
140
-- | Adds a tooltip containing the message @tipText@ to the specified
 
141
-- 'Widget'.
 
142
--
 
143
tooltipsSetTip :: (TooltipsClass self, WidgetClass widget) => self
 
144
 -> widget -- ^ @widget@ - the 'Widget' you wish to associate the tip with.
 
145
 -> String -- ^ @tipText@ - a string containing the tip itself.
 
146
 -> String -- ^ @tipPrivate@ - a string of any further information that may be
 
147
           -- useful if the user gets stuck.
 
148
 -> IO ()
 
149
tooltipsSetTip self widget tipText tipPrivate =
 
150
  withUTFString tipPrivate $ \tipPrivatePtr ->
 
151
  withUTFString tipText $ \tipTextPtr ->
 
152
  {# call unsafe tooltips_set_tip #}
 
153
    (toTooltips self)
 
154
    (toWidget widget)
 
155
    tipTextPtr
 
156
    tipPrivatePtr
 
157
 
 
158
{#pointer * TooltipsData#}
 
159
 
 
160
-- | Retrieves any 'Tooltips' previously associated with the given widget.
 
161
--
 
162
tooltipsDataGet :: WidgetClass w => w -> IO (Maybe (Tooltips, String, String))
 
163
tooltipsDataGet w = do
 
164
  tipDataPtr <- {#call unsafe tooltips_data_get#} (toWidget w)
 
165
  if tipDataPtr == nullPtr
 
166
    then return Nothing
 
167
    else do --next line is a hack, tooltips struct member is at offset 0
 
168
           tooltips <- makeNewObject mkTooltips (return $ castPtr tipDataPtr)
 
169
           tipText  <- {#get TooltipsData->tip_text#} tipDataPtr
 
170
                   >>= peekUTFString
 
171
           tipPrivate <- {#get TooltipsData->tip_private#} tipDataPtr
 
172
                     >>= peekUTFString
 
173
           return $ Just $ (tooltips, tipText, tipPrivate)
 
174