{-# LINE 2 "./Graphics/UI/Gtk/SourceView/SourceMarkAttributes.chs" #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) SourceMarkAttributes
--
-- Author : Hamish Mackenzie
--
-- Created: 20 June 2015
--
-- Copyright (C) 2015 Hamish Mackenzie
--
-- 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 : http:
-- Stability : provisional
-- Portability : portable (depends on GHC)
--
module Graphics.UI.Gtk.SourceView.SourceMarkAttributes (
-- * Description
-- | `SourceMarkAttributes` is an object specifying attributes used by
-- a `SourceView` to visually show lines marked with `SourceMarks` of
-- a specific category. It allows you to define a background color of
-- a line, an icon shown in gutter and tooltips.
--
-- The background color is used as a background of a line where a mark
-- is placed and it can be set with `sourceMarkAttributesSetBackground`.
-- To check if any custom background color was defined and what color
-- it is, use `sourceMarkAttributesGetBackground`.
--
-- An icon is a graphic element which is shown in the gutter of a view.
-- An example use is showing a red filled circle in a debugger to show
-- that a breakpoint was set in certain line. To get an icon that will
-- be placed in a gutter, first a base for it must be specified and
-- then `sourceMarkAttributesRenderIcon` must be called. There are
-- several ways to specify a base for an icon:
--
-- * `sourceMarkAttributesSetIconName`
-- * `sourceMarkAttributesSetGIcon`
-- * `sourceMarkAttributesSetPixbuf`
--
-- Using any of the above functions overrides the one used earlier.
-- But note that a getter counterpart of earlier used function can
-- still return some value, but it is just not used when rendering
-- the proper icon.
--
-- To provide meaningful tooltips for a given mark of a category, you
-- should connect to `queryTooltipText` or `queryTooltipMarkup` where
-- the latter takes precedence.

-- * Types
  SourceMarkAttributes,
  SourceMarkAttributesClass,

-- * Methods
  castToSourceMarkAttributes,
  gTypeSourceMarkAttributes,
  toSourceMarkAttributes,
  sourceMarkAttributesNew,
  sourceMarkAttributesSetBackground,
  sourceMarkAttributesGetBackground,
  sourceMarkAttributesSetIconName,
  sourceMarkAttributesGetIconName,
  sourceMarkAttributesSetPixbuf,
  sourceMarkAttributesGetPixbuf,
  sourceMarkAttributesRenderIcon,
  sourceMarkAttributesGetTooltipText,
  sourceMarkAttributesGetTooltipMarkup,

-- * Attributes
  sourceMarkAttributesBackground,
  sourceMarkAttributesIconName,
  sourceMarkAttributesPixbuf,

-- * Signals
  queryTooltipMarkup,
  queryTooltipText
) where

import Control.Applicative
import Prelude
import Control.Monad (liftM)
import System.Glib.GObject (makeNewGObject)
import System.Glib.Attributes
import System.Glib.FFI
import System.Glib.UTFString

import Graphics.UI.Gtk.Abstract.Object (makeNewObject)
import Graphics.UI.Gtk (RGBA)

import Graphics.UI.Gtk.SourceView.Signals
{-# LINE 99 "./Graphics/UI/Gtk/SourceView/SourceMarkAttributes.chs" #-}
import Graphics.UI.Gtk.SourceView.Types
{-# LINE 100 "./Graphics/UI/Gtk/SourceView/SourceMarkAttributes.chs" #-}


{-# LINE 102 "./Graphics/UI/Gtk/SourceView/SourceMarkAttributes.chs" #-}

-- | Creates a new source mark attributes.
--
sourceMarkAttributesNew :: IO SourceMarkAttributes
sourceMarkAttributesNew = makeNewObject mkSourceMarkAttributes $ liftM castPtr
  gtk_source_mark_attributes_new
{-# LINE 108 "./Graphics/UI/Gtk/SourceView/SourceMarkAttributes.chs" #-}

-- | Sets background color.
--
sourceMarkAttributesSetBackground :: SourceMarkAttributesClass attributes => attributes -> Maybe RGBA -> IO ()
sourceMarkAttributesSetBackground attributes background =
  maybeWith with background $ \ backgroundPtr ->
  (\(SourceMarkAttributes arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_source_mark_attributes_set_background argPtr1 arg2)
{-# LINE 115 "./Graphics/UI/Gtk/SourceView/SourceMarkAttributes.chs" #-}
    (toSourceMarkAttributes attributes)
    (castPtr backgroundPtr)

-- | Gets background color.
--
sourceMarkAttributesGetBackground :: SourceMarkAttributesClass attributes => attributes -> IO (Maybe RGBA)
sourceMarkAttributesGetBackground attributes =
  alloca $ \ rgbaPtr -> do
  isSet <- (\(SourceMarkAttributes arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_source_mark_attributes_get_background argPtr1 arg2)
{-# LINE 124 "./Graphics/UI/Gtk/SourceView/SourceMarkAttributes.chs" #-}
                (toSourceMarkAttributes attributes)
                (castPtr rgbaPtr)
  if isSet /= 0 then Just <$> peek rgbaPtr else return Nothing

-- | Sets a name of an icon to be used as a base for rendered icon.
--
sourceMarkAttributesSetIconName :: (SourceMarkAttributesClass attributes, GlibString iconName)
                                => attributes
                                -> Maybe iconName
                                -> IO ()
sourceMarkAttributesSetIconName attributes iconName =
  maybeWith withUTFString iconName $ \iconNamePtr ->
    (\(SourceMarkAttributes arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_source_mark_attributes_set_icon_name argPtr1 arg2)
{-# LINE 137 "./Graphics/UI/Gtk/SourceView/SourceMarkAttributes.chs" #-}
        (toSourceMarkAttributes attributes)
        iconNamePtr

-- | Gets a name of an icon to be used as a base for rendered icon.
--
sourceMarkAttributesGetIconName :: (SourceMarkAttributesClass attributes, GlibString iconName)
                                => attributes
                                -> IO (Maybe iconName)
sourceMarkAttributesGetIconName attributes =
    (\(SourceMarkAttributes arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_source_mark_attributes_get_icon_name argPtr1)
{-# LINE 147 "./Graphics/UI/Gtk/SourceView/SourceMarkAttributes.chs" #-}
        (toSourceMarkAttributes attributes)
        >>= maybePeek peekUTFString

-- | Sets a pixbuf to be used as a base for rendered icon.
--
sourceMarkAttributesSetPixbuf :: SourceMarkAttributesClass attributes
                              => attributes
                              -> Maybe Pixbuf
                              -> IO ()
sourceMarkAttributesSetPixbuf attributes pixbuf =
    (\(SourceMarkAttributes arg1) (Pixbuf arg2) -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->gtk_source_mark_attributes_set_pixbuf argPtr1 argPtr2)
{-# LINE 158 "./Graphics/UI/Gtk/SourceView/SourceMarkAttributes.chs" #-}
        (toSourceMarkAttributes attributes)
        (maybe (Pixbuf nullForeignPtr) id pixbuf)

-- | Gets a pixbuf to be used as a base for rendered icon.
--
sourceMarkAttributesGetPixbuf :: SourceMarkAttributesClass attributes
                              => attributes
                              -> IO (Maybe Pixbuf)
sourceMarkAttributesGetPixbuf attributes =
  maybeNull (makeNewGObject mkPixbuf) $
    (\(SourceMarkAttributes arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_source_mark_attributes_get_pixbuf argPtr1)
{-# LINE 169 "./Graphics/UI/Gtk/SourceView/SourceMarkAttributes.chs" #-}
        (toSourceMarkAttributes attributes)

-- | Renders an icon of given size. The base of the icon is set by the
-- last call to one of: `sourceMarkAttributesSetPixbuf`,
-- `sourceMarkAttributesSetGIcon` or `sourceMarkAttributessetIconName`.
--
sourceMarkAttributesRenderIcon :: (SourceMarkAttributesClass attributes, WidgetClass widget)
                               => attributes
                               -> widget -- ^ @widget@ of which style settings may be used.
                               -> Int -- ^ @size@ of the redered icon. Cannot be lower than 1
                               -> IO (Maybe Pixbuf)
sourceMarkAttributesRenderIcon attributes widget size =
  maybeNull (makeNewGObject mkPixbuf) $
    (\(SourceMarkAttributes arg1) (Widget arg2) arg3 -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->gtk_source_mark_attributes_render_icon argPtr1 argPtr2 arg3)
{-# LINE 183 "./Graphics/UI/Gtk/SourceView/SourceMarkAttributes.chs" #-}
        (toSourceMarkAttributes attributes)
        (toWidget widget)
        (fromIntegral size)

-- | Queries for a tooltip by emitting a `queryTooltipText` signal. The tooltip is a plain text.
--
sourceMarkAttributesGetTooltipText :: (SourceMarkAttributesClass attributes, SourceMarkClass mark, GlibString text)
                                   => attributes
                                   -> mark
                                   -> IO (Maybe text)
sourceMarkAttributesGetTooltipText attributes mark =
    (\(SourceMarkAttributes arg1) (SourceMark arg2) -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->gtk_source_mark_attributes_get_tooltip_text argPtr1 argPtr2)
{-# LINE 195 "./Graphics/UI/Gtk/SourceView/SourceMarkAttributes.chs" #-}
        (toSourceMarkAttributes attributes)
        (toSourceMark mark)
        >>= maybePeek readUTFString

-- | Queries for a tooltip by emitting a `queryTooltipMarkup` signal. The tooltip may contain a markup.
--
sourceMarkAttributesGetTooltipMarkup :: (SourceMarkAttributesClass attributes, SourceMarkClass mark, GlibString markup)
                                     => attributes
                                     -> mark
                                     -> IO (Maybe markup)
sourceMarkAttributesGetTooltipMarkup attributes mark =
    (\(SourceMarkAttributes arg1) (SourceMark arg2) -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->gtk_source_mark_attributes_get_tooltip_markup argPtr1 argPtr2)
{-# LINE 207 "./Graphics/UI/Gtk/SourceView/SourceMarkAttributes.chs" #-}
        (toSourceMarkAttributes attributes)
        (toSourceMark mark)
        >>= maybePeek readUTFString

-- | A color used for background of a line.
--
sourceMarkAttributesBackground :: SourceMarkAttributesClass attributes => Attr attributes (Maybe RGBA)
sourceMarkAttributesBackground = newAttr sourceMarkAttributesGetBackground sourceMarkAttributesSetBackground

-- | An icon name that may be a base of a rendered icon.
--
sourceMarkAttributesIconName :: (SourceMarkAttributesClass attributes, GlibString iconName) => Attr attributes (Maybe iconName)
sourceMarkAttributesIconName = newAttr sourceMarkAttributesGetIconName sourceMarkAttributesSetIconName

-- | A `Pixbuf` that may be a base of a rendered icon.
--
sourceMarkAttributesPixbuf :: SourceMarkAttributesClass attributes => Attr attributes (Maybe Pixbuf)
sourceMarkAttributesPixbuf = newAttr sourceMarkAttributesGetPixbuf sourceMarkAttributesSetPixbuf


-- | The code should connect to this signal to provide a tooltip for given mark . The tooltip can contain a markup.
--
queryTooltipMarkup :: (SourceMarkAttributesClass self, GlibString markup) => Signal self (SourceMark -> IO markup)
queryTooltipMarkup = Signal (connect_OBJECT__GLIBSTRING "query-tooltip-markup")

-- | The code should connect to this signal to provide a tooltip for given mark . The tooltip should be just a plain text.
--
queryTooltipText :: (SourceMarkAttributesClass self, GlibString text) => Signal self (SourceMark -> IO text)
queryTooltipText = Signal (connect_OBJECT__GLIBSTRING "query-tooltip-text")

foreign import ccall unsafe "gtk_source_mark_attributes_new"
  gtk_source_mark_attributes_new :: (IO (Ptr SourceMarkAttributes))

foreign import ccall unsafe "gtk_source_mark_attributes_set_background"
  gtk_source_mark_attributes_set_background :: ((Ptr SourceMarkAttributes) -> ((Ptr ()) -> (IO ())))

foreign import ccall safe "gtk_source_mark_attributes_get_background"
  gtk_source_mark_attributes_get_background :: ((Ptr SourceMarkAttributes) -> ((Ptr ()) -> (IO CInt)))

foreign import ccall safe "gtk_source_mark_attributes_set_icon_name"
  gtk_source_mark_attributes_set_icon_name :: ((Ptr SourceMarkAttributes) -> ((Ptr CChar) -> (IO ())))

foreign import ccall safe "gtk_source_mark_attributes_get_icon_name"
  gtk_source_mark_attributes_get_icon_name :: ((Ptr SourceMarkAttributes) -> (IO (Ptr CChar)))

foreign import ccall safe "gtk_source_mark_attributes_set_pixbuf"
  gtk_source_mark_attributes_set_pixbuf :: ((Ptr SourceMarkAttributes) -> ((Ptr Pixbuf) -> (IO ())))

foreign import ccall safe "gtk_source_mark_attributes_get_pixbuf"
  gtk_source_mark_attributes_get_pixbuf :: ((Ptr SourceMarkAttributes) -> (IO (Ptr Pixbuf)))

foreign import ccall safe "gtk_source_mark_attributes_render_icon"
  gtk_source_mark_attributes_render_icon :: ((Ptr SourceMarkAttributes) -> ((Ptr Widget) -> (CInt -> (IO (Ptr Pixbuf)))))

foreign import ccall safe "gtk_source_mark_attributes_get_tooltip_text"
  gtk_source_mark_attributes_get_tooltip_text :: ((Ptr SourceMarkAttributes) -> ((Ptr SourceMark) -> (IO (Ptr CChar))))

foreign import ccall safe "gtk_source_mark_attributes_get_tooltip_markup"
  gtk_source_mark_attributes_get_tooltip_markup :: ((Ptr SourceMarkAttributes) -> ((Ptr SourceMark) -> (IO (Ptr CChar))))