From: Duncan C. <dun...@us...> - 2004-04-27 18:51:23
|
Update of /cvsroot/gtk2hs/gtk2hs/gtk/entry In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5286/gtk/entry Modified Files: Entry.chs Added Files: EntryCompletion.chs Log Message: added new gtk 2.4 modules (Expander, ComboBox, ComboBoxEntry, EntryCompletion) and added new methods for Entry. Also exported new modules from main Gtk.hs --- NEW FILE: EntryCompletion.chs --- {-# OPTIONS -cpp #-} -- |GIMP Toolkit (GTK) Binding for Haskell: binding to GConf -*-haskell-*- -- for storing and retrieving configuartion information -- -- Author : Duncan Coutts -- Created: 24 April 2004 -- -- Copyright (c) 2004 Duncan Coutts -- -- This library is free software; you can redistribute it and/or -- modify it under the terms of the GNU Library General Public -- License as published by the Free Software Foundation; either -- version 2 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 -- Library General Public License for more details. -- --- Description --------------------------------------------------------------- -- -- Language: Haskell 98 Binding Module -- -- Completion functionality for the Entry widget. -- -- Added in GTK+ 2.4 -- module EntryCompletion ( EntryCompletion, EntryCompletionClass, entryCompletionNew, entryCompletionGetEntry, entryCompletionSetModel, entryCompletionGetModel, entryCompletionSetMatchFunc, entryCompletionSetMinimumKeyLength, entryCompletionGetMinimumKeyLength, entryCompletionComplete, entryCompletionInsertActionText, entryCompletionInsertActionMarkup, entryCompletionDeleteAction, entryCompletionSetTextColumn ) where import Monad (liftM) import FFI import LocalData (newIORef, readIORef, writeIORef) import GObject (makeNewGObject) import Object (makeNewObject) {#import Hierarchy#} {#import Signal#} {#import TreeModel#} (TreeIter, createTreeIter) {# context lib="gtk" prefix="gtk" #} entryCompletionNew :: IO EntryCompletion entryCompletionNew = makeNewGObject mkEntryCompletion $ liftM castPtr $ {# call gtk_entry_completion_new #} entryCompletionGetEntry :: EntryCompletion -> IO (Maybe Entry) entryCompletionGetEntry ec = do entryPtr <- {# call gtk_entry_completion_get_entry #} ec if entryPtr == nullPtr then return Nothing else liftM Just $ makeNewObject mkEntry $ return (castPtr entryPtr) entryCompletionSetModel :: EntryCompletion -> TreeModel -> IO () entryCompletionSetModel ec tm = {# call gtk_entry_completion_set_model #} ec tm entryCompletionGetModel :: EntryCompletion -> IO TreeModel entryCompletionGetModel ec = makeNewGObject mkTreeModel $ {# call gtk_entry_completion_get_model #} ec entryCompletionSetMatchFunc :: EntryCompletion -> (String -> TreeIter -> IO ()) -> IO () entryCompletionSetMatchFunc ec handler = connect_GtkEntryCompletionMatchFunc ec handler entryCompletionSetMinimumKeyLength :: EntryCompletion -> Int -> IO () entryCompletionSetMinimumKeyLength ec minLength = {# call gtk_entry_completion_set_minimum_key_length #} ec (fromIntegral minLength) entryCompletionGetMinimumKeyLength :: EntryCompletion -> IO Int entryCompletionGetMinimumKeyLength ec = liftM fromIntegral $ {# call gtk_entry_completion_get_minimum_key_length #} ec entryCompletionComplete :: EntryCompletion -> IO () entryCompletionComplete ec = {# call gtk_entry_completion_complete #} ec entryCompletionInsertActionText :: EntryCompletion -> Int -> String -> IO () entryCompletionInsertActionText ec index text = withUTFString text $ \strPtr -> {# call gtk_entry_completion_insert_action_text #} ec (fromIntegral index) strPtr entryCompletionInsertActionMarkup :: EntryCompletion -> Int -> String -> IO () entryCompletionInsertActionMarkup ec index markup = withUTFString markup $ \strPtr -> {# call gtk_entry_completion_insert_action_markup #} ec (fromIntegral index) strPtr entryCompletionDeleteAction :: EntryCompletion -> Int -> IO () entryCompletionDeleteAction ec index = {# call gtk_entry_completion_delete_action #} ec (fromIntegral index) entryCompletionSetTextColumn :: EntryCompletion -> Int -> IO () entryCompletionSetTextColumn ec column = {# call gtk_entry_completion_set_text_column #} ec (fromIntegral column) ------------------------------------------------- -- Callback stuff for entryCompletionSetMatchFunc -- {#pointer GDestroyNotify#} #if __GLASGOW_HASKELL__>=504 foreign import ccall "wrapper" mkDestructor :: IO () -> IO GDestroyNotify #else foreign export dynamic mkDestructor :: IO () -> IO GDestroyNotify #endif type GtkEntryCompletionMatchFunc = Ptr EntryCompletion -> --GtkEntryCompletion *completion Ptr CChar -> --const gchar *key Ptr TreeIter -> --GtkTreeIter *iter Ptr () -> --gpointer user_data IO () #if __GLASGOW_HASKELL__>=504 foreign import ccall "wrapper" mkHandler_GtkEntryCompletionMatchFunc :: GtkEntryCompletionMatchFunc -> IO (FunPtr GtkEntryCompletionMatchFunc) #else foreign export dynamic mkHandler_GtkEntryCompletionMatchFunc :: GtkEntryCompletionMatchFunc -> IO (FunPtr GtkEntryCompletionMatchFunc) #endif connect_GtkEntryCompletionMatchFunc :: EntryCompletion -> (String -> TreeIter -> IO ()) -> IO () connect_GtkEntryCompletionMatchFunc ec user = do hPtr <- mkHandler_GtkEntryCompletionMatchFunc (\_ keyPtr iterPtr _ -> do key <- peekUTFString keyPtr iter <- createTreeIter iterPtr user key iter) dRef <- newIORef nullFunPtr dPtr <- mkDestructor $ do freeHaskellFunPtr hPtr dPtr <- readIORef dRef freeHaskellFunPtr dPtr writeIORef dRef dPtr {# call gtk_entry_completion_set_match_func #} ec (castFunPtr hPtr) nullPtr dPtr Index: Entry.chs =================================================================== RCS file: /cvsroot/gtk2hs/gtk2hs/gtk/entry/Entry.chs,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Entry.chs 9 Jul 2003 22:42:43 -0000 1.7 +++ Entry.chs 27 Apr 2004 18:51:14 -0000 1.8 @@ -1,3 +1,4 @@ +{-# OPTIONS -cpp #-} -- -*-haskell-*- -- GIMP Toolkit (GTK) @entry Widget Entry@ -- @@ -31,6 +32,8 @@ -- * A couple of signals are not bound because I could not figure out what -- they mean. Some of them do not seem to be emitted at all. -- +#include <gtk/gtkversion.h> + module Entry( Entry, EntryClass, @@ -59,6 +62,10 @@ entrySetHasFrame, entryGetWidthChars, entrySetWidthChars, +#if GTK_CHECK_VERSION(2,4,0) + entrySetCompletion, + entryGetCompletion, +#endif onEntryActivate, afterEntryActivate, onEntryChanged, @@ -81,6 +88,7 @@ import FFI import Object (makeNewObject) +import GObject (makeNewGObject) {#import Hierarchy#} {#import Signal#} import Char (ord) @@ -299,6 +307,28 @@ entrySetWidthChars ec setting = {#call entry_set_width_chars#} (toEntry ec) (fromIntegral setting) +#if GTK_CHECK_VERSION(2,4,0) +-- @method entrySetCompletion@ Sets the auxiliary completion object to use with +-- the entry. All further configuration of the completion mechanism is done on +-- completion using the GtkEntryCompletion API. +-- +-- * Since gtk 2.4 +-- +entrySetCompletion :: EntryClass ec => ec -> EntryCompletion -> IO () +entrySetCompletion ec completion = {#call gtk_entry_set_completion#} + (toEntry ec) completion + +-- @method entryGetCompletion@ Returns the auxiliary completion object currently +-- in use by entry +-- +-- * Since gtk 2.4 +-- +entryGetCompletion :: EntryClass ec => ec -> IO EntryCompletion +entryGetCompletion ec = + makeNewGObject mkEntryCompletion $ + {#call gtk_entry_get_completion#} (toEntry ec) +#endif + -- signals |