{-# LINE 2 "./Graphics/UI/Gtk/SourceView/SourceCompletionContext.chs" #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Widget SourceCompletionContext
--
-- Author : Andy Stewart
--
-- Created: 08 Aug 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)
--
module Graphics.UI.Gtk.SourceView.SourceCompletionContext (
-- * Types
   SourceCompletionContext,
   SourceCompletionContextClass,

-- * Enums
   SourceCompletionActivation,

-- * Methods
   sourceCompletionContextAddProposals,
   sourceCompletionContextGetIter,

-- * Attributes
   sourceCompletionContextActivation,
   sourceCompletionContextCompletion,

-- * Signals
   sourceCompletionContextCancelled,
) where

import Control.Monad (liftM)

import Graphics.UI.Gtk.SourceView.Enums
import System.Glib.Attributes
import System.Glib.FFI
import System.Glib.GList (fromGList, withGList)
import System.Glib.Properties
import System.Glib.UTFString

import Graphics.UI.Gtk.SourceView.Signals
{-# LINE 56 "./Graphics/UI/Gtk/SourceView/SourceCompletionContext.chs" #-}
import Graphics.UI.Gtk.SourceView.Types
{-# LINE 57 "./Graphics/UI/Gtk/SourceView/SourceCompletionContext.chs" #-}


{-# LINE 59 "./Graphics/UI/Gtk/SourceView/SourceCompletionContext.chs" #-}

-- | Providers can use this function to add proposals to the completion. They can do so asynchronously by
-- means of the finished argument. Providers must ensure that they always call this function with
-- finished set to 'True' once each population (even if no proposals need to be added).
sourceCompletionContextAddProposals :: SourceCompletionContextClass scc => scc
                                    -> SourceCompletionProvider
                                    -> [SourceCompletionProposal] -- ^ @proposals@ The list of proposals to add
                                    -> Bool -- ^ @finished@ Whether the provider is finished adding proposals
                                    -> IO ()
sourceCompletionContextAddProposals scc provider proposals finished =
    withForeignPtrs (map unSourceCompletionProposal proposals) $ \proposalsPtr ->
    withForeignPtr (unSourceCompletionProvider provider) $ \providerPtr ->
    withGList proposalsPtr $ \glist ->
    (\(SourceCompletionContext arg1) arg2 arg3 arg4 -> withForeignPtr arg1 $ \argPtr1 ->gtk_source_completion_context_add_proposals argPtr1 arg2 arg3 arg4)
{-# LINE 73 "./Graphics/UI/Gtk/SourceView/SourceCompletionContext.chs" #-}
      (toSourceCompletionContext scc)
      (castPtr providerPtr)
      glist
      (fromBool finished)

-- | Get the iter at which the completion was invoked. Providers can use this to determine how and if to
-- match proposals.
sourceCompletionContextGetIter :: SourceCompletionContextClass scc => scc
                               -> IO TextIter
sourceCompletionContextGetIter scc = do
  iter <- makeEmptyTextIter
  (\(SourceCompletionContext arg1) (TextIter arg2) -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->gtk_source_completion_context_get_iter argPtr1 argPtr2)
{-# LINE 85 "./Graphics/UI/Gtk/SourceView/SourceCompletionContext.chs" #-}
    (toSourceCompletionContext scc)
    iter
  return iter

-- | The completion activation
sourceCompletionContextActivation :: SourceCompletionContextClass scc => Attr scc SourceCompletionActivation
sourceCompletionContextActivation = newAttrFromEnumProperty "activation"
                                    gtk_source_completion_activation_get_type
{-# LINE 93 "./Graphics/UI/Gtk/SourceView/SourceCompletionContext.chs" #-}

-- | The 'SourceCompletion' associated with the context.
sourceCompletionContextCompletion :: SourceCompletionContextClass scc => Attr scc SourceCompletion
sourceCompletionContextCompletion = newAttrFromObjectProperty "completion"
                                    gtk_source_completion_get_type
{-# LINE 98 "./Graphics/UI/Gtk/SourceView/SourceCompletionContext.chs" #-}

-- | Emitted when the current population of proposals has been cancelled. Providers adding proposals
-- asynchronously should connect to this signal to know when to cancel running proposal queries.
sourceCompletionContextCancelled :: SourceCompletionContextClass scc => Signal scc (IO ())
sourceCompletionContextCancelled = Signal $ connect_NONE__NONE "cancelled"

foreign import ccall safe "gtk_source_completion_context_add_proposals"
  gtk_source_completion_context_add_proposals :: ((Ptr SourceCompletionContext) -> ((Ptr ()) -> ((Ptr ()) -> (CInt -> (IO ())))))

foreign import ccall safe "gtk_source_completion_context_get_iter"
  gtk_source_completion_context_get_iter :: ((Ptr SourceCompletionContext) -> ((Ptr TextIter) -> (IO ())))

foreign import ccall unsafe "gtk_source_completion_activation_get_type"
  gtk_source_completion_activation_get_type :: CUInt

foreign import ccall unsafe "gtk_source_completion_get_type"
  gtk_source_completion_get_type :: CUInt