{-# LINE 2 "./Graphics/UI/Gtk/Buttons/LinkButton.chs" #-}
-- -*-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
-- @


-- * Types
  LinkButton,
  LinkButtonClass,
  castToLinkButton,
  toLinkButton,

-- * Constructors
  linkButtonNew,
  linkButtonNewWithLabel,

-- * Methods

  linkButtonSetUriHook,


-- * Attributes
  linkButtonURI,

  linkButtonVisited,


  ) 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
{-# LINE 95 "./Graphics/UI/Gtk/Buttons/LinkButton.chs" #-}


{-# LINE 97 "./Graphics/UI/Gtk/Buttons/LinkButton.chs" #-}



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

-- | Creates a new 'LinkButton' with the URI as its text.
--
linkButtonNew :: GlibString string
 => string -- ^ @uri@ - a valid URI
 -> IO LinkButton
linkButtonNew :: forall string. GlibString string => string -> IO LinkButton
linkButtonNew string
uri =
  (ForeignPtr LinkButton -> LinkButton, FinalizerPtr LinkButton)
-> IO (Ptr LinkButton) -> IO LinkButton
forall obj.
ObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
makeNewObject (ForeignPtr LinkButton -> LinkButton, FinalizerPtr LinkButton)
forall {a}. (ForeignPtr LinkButton -> LinkButton, FinalizerPtr a)
mkLinkButton (IO (Ptr LinkButton) -> IO LinkButton)
-> IO (Ptr LinkButton) -> IO LinkButton
forall a b. (a -> b) -> a -> b
$
  (Ptr Widget -> Ptr LinkButton)
-> IO (Ptr Widget) -> IO (Ptr LinkButton)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Ptr Widget -> Ptr LinkButton
forall a b. Ptr a -> Ptr b
castPtr :: Ptr Widget -> Ptr LinkButton) (IO (Ptr Widget) -> IO (Ptr LinkButton))
-> IO (Ptr Widget) -> IO (Ptr LinkButton)
forall a b. (a -> b) -> a -> b
$
  string -> (CString -> IO (Ptr Widget)) -> IO (Ptr Widget)
forall a. string -> (CString -> IO a) -> IO a
forall s a. GlibString s => s -> (CString -> IO a) -> IO a
withUTFString string
uri ((CString -> IO (Ptr Widget)) -> IO (Ptr Widget))
-> (CString -> IO (Ptr Widget)) -> IO (Ptr Widget)
forall a b. (a -> b) -> a -> b
$ \CString
uriPtr ->
  CString -> IO (Ptr Widget)
gtk_link_button_new
{-# LINE 113 "./Graphics/UI/Gtk/Buttons/LinkButton.chs" #-}
    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 :: forall string.
GlibString string =>
string -> string -> IO LinkButton
linkButtonNewWithLabel string
uri string
label =
  (ForeignPtr LinkButton -> LinkButton, FinalizerPtr LinkButton)
-> IO (Ptr LinkButton) -> IO LinkButton
forall obj.
ObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
makeNewObject (ForeignPtr LinkButton -> LinkButton, FinalizerPtr LinkButton)
forall {a}. (ForeignPtr LinkButton -> LinkButton, FinalizerPtr a)
mkLinkButton (IO (Ptr LinkButton) -> IO LinkButton)
-> IO (Ptr LinkButton) -> IO LinkButton
forall a b. (a -> b) -> a -> b
$
  (Ptr Widget -> Ptr LinkButton)
-> IO (Ptr Widget) -> IO (Ptr LinkButton)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Ptr Widget -> Ptr LinkButton
forall a b. Ptr a -> Ptr b
castPtr :: Ptr Widget -> Ptr LinkButton) (IO (Ptr Widget) -> IO (Ptr LinkButton))
-> IO (Ptr Widget) -> IO (Ptr LinkButton)
forall a b. (a -> b) -> a -> b
$
  string -> (CString -> IO (Ptr Widget)) -> IO (Ptr Widget)
forall a. string -> (CString -> IO a) -> IO a
forall s a. GlibString s => s -> (CString -> IO a) -> IO a
withUTFString string
label ((CString -> IO (Ptr Widget)) -> IO (Ptr Widget))
-> (CString -> IO (Ptr Widget)) -> IO (Ptr Widget)
forall a b. (a -> b) -> a -> b
$ \CString
labelPtr ->
  string -> (CString -> IO (Ptr Widget)) -> IO (Ptr Widget)
forall a. string -> (CString -> IO a) -> IO a
forall s a. GlibString s => s -> (CString -> IO a) -> IO a
withUTFString string
uri ((CString -> IO (Ptr Widget)) -> IO (Ptr Widget))
-> (CString -> IO (Ptr Widget)) -> IO (Ptr Widget)
forall a b. (a -> b) -> a -> b
$ \CString
uriPtr ->
  CString -> CString -> IO (Ptr Widget)
gtk_link_button_new_with_label
{-# LINE 127 "./Graphics/UI/Gtk/Buttons/LinkButton.chs" #-}
    uriPtr
    CString
labelPtr

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

-- | 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 :: (String -> IO ()) -> IO ()
linkButtonSetUriHook String -> IO ()
func = do
  LinkButtonUriFunc
pfPtr <- (Ptr LinkButton -> CString -> Ptr () -> IO ())
-> IO LinkButtonUriFunc
mkLinkButtonUriFunc ((Ptr LinkButton -> CString -> Ptr () -> IO ())
 -> IO LinkButtonUriFunc)
-> (Ptr LinkButton -> CString -> Ptr () -> IO ())
-> IO LinkButtonUriFunc
forall a b. (a -> b) -> a -> b
$ \Ptr LinkButton
_ CString
cstr Ptr ()
_ -> do
      String
str <- CString -> IO String
peekCString CString
cstr
      String -> IO ()
func String
str
  LinkButtonUriFunc
-> Ptr () -> FunPtr (Ptr () -> IO ()) -> IO LinkButtonUriFunc
gtk_link_button_set_uri_hook LinkButtonUriFunc
pfPtr (LinkButtonUriFunc -> Ptr ()
forall a b. FunPtr a -> Ptr b
castFunPtrToPtr LinkButtonUriFunc
pfPtr) FunPtr (Ptr () -> IO ())
destroyFunPtr
  LinkButtonUriFunc -> IO ()
forall a. FunPtr a -> IO ()
freeHaskellFunPtr LinkButtonUriFunc
pfPtr

type LinkButtonUriFunc = FunPtr (((Ptr LinkButton) -> ((Ptr CChar) -> ((Ptr ()) -> (IO ())))))
{-# LINE 149 "./Graphics/UI/Gtk/Buttons/LinkButton.chs" #-}

foreign import ccall "wrapper" mkLinkButtonUriFunc ::
  (Ptr LinkButton -> CString -> Ptr () -> IO ())
  -> IO LinkButtonUriFunc


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

-- | The URI bound to this button.
--
-- Default value: \"\"
--
-- * Available since Gtk+ version 2.10
--
linkButtonURI :: (LinkButtonClass self, GlibString string) => Attr self string
linkButtonURI :: forall self string.
(LinkButtonClass self, GlibString string) =>
Attr self string
linkButtonURI = String -> Attr self string
forall gobj string.
(GObjectClass gobj, GlibString string) =>
String -> Attr gobj string
newAttrFromStringProperty String
"uri"


-- | 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 :: forall self. LinkButtonClass self => Attr self Bool
linkButtonVisited = String -> Attr self Bool
forall gobj. GObjectClass gobj => String -> Attr gobj Bool
newAttrFromBoolProperty String
"visited"

foreign import ccall safe "gtk_link_button_new"
  gtk_link_button_new :: ((Ptr CChar) -> (IO (Ptr Widget)))

foreign import ccall safe "gtk_link_button_new_with_label"
  gtk_link_button_new_with_label :: ((Ptr CChar) -> ((Ptr CChar) -> (IO (Ptr Widget))))

foreign import ccall safe "gtk_link_button_set_uri_hook"
  gtk_link_button_set_uri_hook :: ((FunPtr ((Ptr LinkButton) -> ((Ptr CChar) -> ((Ptr ()) -> (IO ()))))) -> ((Ptr ()) -> ((FunPtr ((Ptr ()) -> (IO ()))) -> (IO (FunPtr ((Ptr LinkButton) -> ((Ptr CChar) -> ((Ptr ()) -> (IO ())))))))))