From: Duncan C. <dun...@us...> - 2005-01-08 16:05:17
|
Update of /cvsroot/gtk2hs/gtk2hs/sourceview/Graphics/UI/Gtk/SourceView In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9603/sourceview/Graphics/UI/Gtk/SourceView Added Files: SourceTagStyle.hsc SourceTagTable.chs SourceStyleScheme.chs Log Message: sourceview package hierarchical namespace conversion. --- NEW FILE: SourceTagStyle.hsc --- -- -*-haskell-*- -- GIMP Toolkit (GTK) SourceTagStyle -- -- Author : Duncan Coutts -- derived from GtkTextView bindings by Axel Simon -- -- Created: 20 October 2003 -- -- This file is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This file 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 General Public License for more details. -- -- | -- module Graphics.UI.Gtk.SourceView.SourceTagStyle ( SourceTagStyle(..), ) where import Maybe (isJust, fromMaybe) import Data.Bits (testBit, bit, (.|.)) import System.Glib.FFI import Graphics.UI.Gtk.General.Structs (Color(..)) #include <gtksourceview/gtksourcetagstyle.h> data SourceTagStyleMask = SourceTagStyleUseBackground | SourceTagStyleUseForeground deriving (Eq) instance Enum SourceTagStyleMask where fromEnum SourceTagStyleUseBackground = 1 fromEnum SourceTagStyleUseForeground = 2 toEnum 1 = SourceTagStyleUseBackground toEnum 2 = SourceTagStyleUseForeground toEnum unmatched = error ("SourceTagStyleMask.toEnum: Cannot match " ++ show unmatched) data SourceTagStyle = SourceTagStyle { isDefault :: Bool, -- readonly foreground :: Maybe Color, background :: Maybe Color, italic :: Bool, bold :: Bool, underline :: Bool, strikethrough :: Bool } instance Storable SourceTagStyle where sizeOf _ = #{const sizeof(GtkSourceTagStyle)} alignment _ = alignment (undefined::#type gboolean) peek ptr = do (isDefault'::#type gboolean) <- #{peek GtkSourceTagStyle, is_default} ptr (mask::#type guint) <- #{peek GtkSourceTagStyle, mask} ptr foreground' <- peek (#{ptr GtkSourceTagStyle, foreground} ptr) background' <- peek (#{ptr GtkSourceTagStyle, background} ptr) (italic'::#type gboolean) <- #{peek GtkSourceTagStyle, italic} ptr (bold'::#type gboolean) <- #{peek GtkSourceTagStyle, bold} ptr (underline'::#type gboolean) <- #{peek GtkSourceTagStyle, underline} ptr (strikethrough'::#type gboolean) <- #{peek GtkSourceTagStyle, strikethrough} ptr return SourceTagStyle { isDefault = toBool isDefault', foreground = if mask `testBit` (fromEnum SourceTagStyleUseForeground) then Just foreground' else Nothing, background = if mask `testBit` (fromEnum SourceTagStyleUseBackground) then Just background' else Nothing, italic = toBool italic', bold = toBool bold', underline = toBool underline', strikethrough = toBool strikethrough' } poke ptr tag = do #{poke GtkSourceTagStyle, is_default} ptr (fromBool $ isDefault tag ::#type gboolean) #{poke GtkSourceTagStyle, mask} ptr ((if isJust (foreground tag) then bit (fromEnum SourceTagStyleUseForeground) else 0) .|.(if isJust (background tag) then bit (fromEnum SourceTagStyleUseBackground) else 0) ::#type guint) poke (#{ptr GtkSourceTagStyle, foreground} ptr) (fromMaybe (Color 0 0 0) (foreground tag)) poke (#{ptr GtkSourceTagStyle, background} ptr) (fromMaybe (Color 0 0 0) (background tag)) #{poke GtkSourceTagStyle, italic} ptr (fromBool $ italic tag ::#type gboolean) #{poke GtkSourceTagStyle, bold} ptr (fromBool $ bold tag ::#type gboolean) #{poke GtkSourceTagStyle, underline} ptr (fromBool $ underline tag ::#type gboolean) #{poke GtkSourceTagStyle, strikethrough} ptr (fromBool $ strikethrough tag ::#type gboolean) --- NEW FILE: SourceTagTable.chs --- -- -*-haskell-*- -- GIMP Toolkit (GTK) SourceTagTable -- -- Author : Duncan Coutts -- derived from GtkTextView bindings by Axel Simon -- -- Created: 22 October 2003 -- -- This file is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This file 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 General Public License for more details. -- -- | -- module Graphics.UI.Gtk.SourceView.SourceTagTable ( SourceTagTable, SourceTagTableClass, sourceTagTableNew, sourceTagTableAddTags, sourceTagTableRemoveSourceTags ) where import Monad (liftM) import System.Glib.FFI import System.Glib.GList (fromGSList, toGSList) import System.Glib.GObject (makeNewGObject) {#import Graphics.UI.Gtk.Types#} {#import Graphics.UI.Gtk.SourceView.Types#} {#import Graphics.UI.Gtk.Signals#} import Graphics.UI.Gtk.SourceView.SourceTag {# context lib="gtk" prefix="gtk" #} -- methods -- | Create a new 'SourceTagTable' -- sourceTagTableNew :: IO SourceTagTable sourceTagTableNew = makeNewGObject mkSourceTagTable {#call unsafe source_tag_table_new#} -- | Add a list of tag to the table. -- -- * The added tags are assigned the highest priority in the table. If a tag is -- already present in table or has the same name as an already-added tag, then -- it is not added to the table. -- sourceTagTableAddTags :: SourceTagTable -> [SourceTag] -> IO () sourceTagTableAddTags tt tags = do let tagForeignPtrs = map (unSourceTag . toSourceTag) tags tagList <- toGSList (map foreignPtrToPtr tagForeignPtrs) {#call source_tag_table_add_tags#} tt tagList -- destroy the list fromGSList tagList -- make sure the ForeignPtrs are not gc'd while we are still using the Ptrs mapM_ touchForeignPtr tagForeignPtrs -- | -- sourceTagTableRemoveSourceTags :: SourceTagTable -> IO () sourceTagTableRemoveSourceTags tt = {#call source_tag_table_remove_source_tags#} tt -- | The source tag table has changed. -- onTagChanged, afterTagChanged :: SourceTagTableClass stt => stt -> IO () -> IO (ConnectId stt) onTagChanged = connect_NONE__NONE "changed" False afterTagChanged = connect_NONE__NONE "changed" True --- NEW FILE: SourceStyleScheme.chs --- -- -*-haskell-*- -- GIMP Toolkit (GTK) SourceStyleScheme -- -- Author : Duncan Coutts -- derived from the GtkTextView bindings by Axel Simon -- -- Created: 22 October 2003 -- -- This file is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This file 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 General Public License for more details. -- -- | -- module Graphics.UI.Gtk.SourceView.SourceStyleScheme ( SourceStyleScheme, sourceStyleSchemeGetTagStyle, sourceStyleSchemeGetName, sourceStyleSchemeGetDefault ) where import Monad (liftM) import System.Glib.FFI import System.Glib.UTFString import System.Glib.GObject (makeNewGObject) {#import Graphics.UI.Gtk.Types#} {#import Graphics.UI.Gtk.SourceView.Types#} import Graphics.UI.Gtk.SourceView.SourceTagStyle {# context lib="gtk" prefix="gtk" #} -- methods -- | -- sourceStyleSchemeGetTagStyle :: SourceStyleScheme -> String -> IO SourceTagStyle sourceStyleSchemeGetTagStyle ss styleName = withCString styleName $ \strPtr -> do tsPtr <- {#call source_style_scheme_get_tag_style#} ss strPtr ts <- peek (castPtr tsPtr) {#call unsafe g_free#} tsPtr return ts -- | -- sourceStyleSchemeGetName :: SourceStyleScheme -> IO String sourceStyleSchemeGetName ss = {#call source_style_scheme_get_name#} ss >>= peekUTFString -- | -- sourceStyleSchemeGetDefault :: IO SourceStyleScheme sourceStyleSchemeGetDefault = makeNewGObject mkSourceStyleScheme $ liftM castPtr $ {#call source_style_scheme_get_default#} |