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
|
{-# LANGUAGE CPP #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Widget LinkButton
--
-- Author : Andy Stewart
--
-- Created: 22 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.
--
-- |
-- Maintainer : gtk2hs-users@lists.sourceforge.net
-- Stability : provisional
-- Portability : portable (depends on GHC)
--
-- Create buttons bound to a URL
--
-- * Module available since Gtk+ version 2.10
--
module Graphics.UI.Gtk.Buttons.LinkButton (
-- * Detail
--
-- | A 'LinkButton' is a 'Button' with a hyperlink, similar to the one used by
-- web browsers, which triggers an action when clicked. It is useful to show
-- quick links to resources.
--
-- A link button is created by calling either 'linkButtonNew' or
-- 'linkButtonNewWithLabel'. If using the former, the URI you pass to the
-- constructor is used as a label for the widget.
--
-- The URI bound to a 'LinkButton' can be set specifically using
-- \"set linkButton [linkButtonURI := uri]\", and retrieved using \"uri <- get linkButton linkButtonURI\".
--
-- 'LinkButton' offers a global hook, which is called when the used clicks
-- on it: see 'linkButtonSetURIHook'.
--
-- 'LinkButton' was added in Gtk+ 2.10.
-- * Class Hierarchy
--
-- |
-- @
-- | 'GObject'
-- | +----'Object'
-- | +----'Widget'
-- | +----'Container'
-- | +----'Bin'
-- | +----'Button'
-- | +----LinkButton
-- @
#if GTK_CHECK_VERSION(2,10,0)
-- * Types
LinkButton,
LinkButtonClass,
castToLinkButton,
toLinkButton,
-- * Constructors
linkButtonNew,
linkButtonNewWithLabel,
-- * Methods
#if GTK_MAJOR_VERSION < 3
linkButtonSetUriHook,
#endif
-- * Attributes
linkButtonURI,
#if GTK_CHECK_VERSION(2,14,0)
linkButtonVisited,
#endif
#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.Types#}
{# context lib="gtk" prefix="gtk" #}
#if GTK_CHECK_VERSION(2,10,0)
--------------------
-- Constructors
-- | Creates a new 'LinkButton' with the URI as its text.
--
linkButtonNew :: GlibString string
=> string -- ^ @uri@ - a valid URI
-> IO LinkButton
linkButtonNew uri =
makeNewObject mkLinkButton $
liftM (castPtr :: Ptr Widget -> Ptr LinkButton) $
withUTFString uri $ \uriPtr ->
{# call gtk_link_button_new #}
uriPtr
-- | Creates a new 'LinkButton' containing a label.
--
linkButtonNewWithLabel :: GlibString string
=> string -- ^ @uri@ - a valid URI
-> string -- ^ @label@ - the text of the button
-> IO LinkButton
linkButtonNewWithLabel uri label =
makeNewObject mkLinkButton $
liftM (castPtr :: Ptr Widget -> Ptr LinkButton) $
withUTFString label $ \labelPtr ->
withUTFString uri $ \uriPtr ->
{# call gtk_link_button_new_with_label #}
uriPtr
labelPtr
--------------------
-- Methods
#if GTK_MAJOR_VERSION < 3
-- | Sets @func@ as the function that should be invoked every time a user
-- clicks a 'LinkButton'. This function is called before every callback
-- registered for the 'buttonClicked' signal.
--
-- If no uri hook has been set, Gtk+ defaults to calling 'showURI'.
--
-- Removed in Gtk3.
linkButtonSetUriHook :: (String -> IO ()) -> IO ()
linkButtonSetUriHook func = do
pfPtr <- mkLinkButtonUriFunc $ \_ cstr _ -> do
str <- peekCString cstr
func str
{# call link_button_set_uri_hook #} pfPtr (castFunPtrToPtr pfPtr) destroyFunPtr
freeHaskellFunPtr pfPtr
{#pointer LinkButtonUriFunc#}
foreign import ccall "wrapper" mkLinkButtonUriFunc ::
(Ptr LinkButton -> CString -> Ptr () -> IO ())
-> IO LinkButtonUriFunc
#endif
--------------------
-- Attributes
-- | The URI bound to this button.
--
-- Default value: \"\"
--
-- * Available since Gtk+ version 2.10
--
linkButtonURI :: (LinkButtonClass self, GlibString string) => Attr self string
linkButtonURI = newAttrFromStringProperty "uri"
#if GTK_CHECK_VERSION(2,14,0)
-- | The 'visited' state of this button. A visited link is drawn in a different color.
--
-- Default value: 'False'
--
-- * Available since Gtk+ version 2.14
--
linkButtonVisited :: LinkButtonClass self => Attr self Bool
linkButtonVisited = newAttrFromBoolProperty "visited"
#endif
#endif
|