From: Andy S. <And...@co...> - 2010-04-02 18:27:26
|
Fri Apr 2 14:26:25 EDT 2010 Andy Stewart <laz...@gm...> * Add miscellaneous Gtk+ modules, and fix some functions. Ignore-this: cf8f39a7c6c9e8e77f8e3ec8970b122b hunk ./ApiUpdateTodoList.txt 4 --- Before that, we will convert tag `TODO` to tag `FINISH` +-- Before that, we will convert tag `TODO` to tag `DONE` hunk ./ApiUpdateTodoList.txt 8 --- So please make sure convert `FINISH` tag here to avoid duplicate work. +-- So please make sure convert `DONE` tag here to avoid duplicate work. hunk ./ApiUpdateTodoList.txt 18 -*** TODO Accel.chs -*** TODO Accelerator.chs -*** TODO AccelGroup.chs -*** TODO AccelMap.chs -*** TODO Accessible.chs +*** DONE Accel.chs +*** DONE Accelerator.chs +*** DONE AccelGroup.chs +*** DONE AccelMap.chs +*** DONE Accessible.chs hunk ./ApiUpdateTodoList.txt 26 -*** TODO Bindings.chs -*** TODO Bitmap.chs +*** DONE Bindings.chs +*** DONE Bitmap.chs hunk ./ApiUpdateTodoList.txt 29 -*** TODO Buildable.chs +*** DONE Buildable.chs hunk ./ApiUpdateTodoList.txt 34 -*** TODO Char.chs +*** DONE Char.chs hunk ./ApiUpdateTodoList.txt 38 -*** TODO Colors.chs +*** DONE Colors.chs hunk ./ApiUpdateTodoList.txt 42 -*** TODO CustomPaperUnixDialog.chs +*** DONE CustomPaperUnixDialog.chs hunk ./ApiUpdateTodoList.txt 53 -*** TODO FileChooserEmbed.chs +*** DONE FileChooserEmbed.chs hunk ./ApiUpdateTodoList.txt 60 -*** TODO Grab.chs +*** DONE Grab.chs hunk ./ApiUpdateTodoList.txt 63 -*** TODO Icon.chs +*** DONE Icon.chs hunk ./ApiUpdateTodoList.txt 65 -*** TODO IconSet.chs -*** TODO IconSource.chs +*** DONE IconSet.chs +*** DONE IconSource.chs hunk ./ApiUpdateTodoList.txt 68 -*** TODO Idle.chs +*** DONE Idle.chs hunk ./ApiUpdateTodoList.txt 71 -*** TODO Init.chs -*** TODO Input.chs +*** DONE Init.chs +*** DONE Input.chs hunk ./ApiUpdateTodoList.txt 74 -*** TODO Invisible.chs -*** TODO Item.chs +*** DONE Invisible.chs +*** DONE Item.chs hunk ./ApiUpdateTodoList.txt 84 -*** TODO Main.chs -*** TODO MountOperation.chs +*** DONE Main.chs +*** DONE MountOperation.chs hunk ./ApiUpdateTodoList.txt 124 -*** TODO Quit.chs -*** TODO Rc.chs -*** TODO RcStyle.chs +*** DONE Quit.chs +*** DONE Rc.chs +*** DONE RcStyle.chs hunk ./ApiUpdateTodoList.txt 137 -*** TODO Requisition.chs +*** DONE Requisition.chs hunk ./ApiUpdateTodoList.txt 141 -*** TODO Screen.chs -*** TODO SearchEngineBeagle.chs -*** TODO SearchEngine.chs -*** TODO SearchEngineQuartz.chs -*** TODO SearchEngineSimple.chs -*** TODO SearchEngineTracker.chs -*** TODO SelectionData.chs +*** DONE Screen.chs +*** DONE SearchEngineBeagle.chs +*** DONE SearchEngine.chs +*** DONE SearchEngineQuartz.chs +*** DONE SearchEngineSimple.chs +*** DONE SearchEngineTracker.chs +*** DONE SelectionData.chs hunk ./ApiUpdateTodoList.txt 149 -*** TODO Signal.chs +*** DONE Signal.chs hunk ./ApiUpdateTodoList.txt 151 -*** TODO Stock.chs -*** TODO Target.chs -*** TODO TargetList.chs -*** TODO Targets.chs -*** TODO TextAttributes.chs -*** TODO TextChildAnchor.chs +*** DONE Stock.chs +*** DONE Target.chs +*** DONE TargetList.chs +*** DONE Targets.chs +*** DONE TextAttributes.chs +*** DONE TextChildAnchor.chs hunk ./ApiUpdateTodoList.txt 159 -*** TODO Timeout.chs +*** DONE Timeout.chs hunk ./ApiUpdateTodoList.txt 163 -*** TODO TrayIcon.chs +*** DONE TrayIcon.chs hunk ./ApiUpdateTodoList.txt 165 -*** TODO TreeDragDest.chs -*** TODO TreeDragSource.chs -*** TODO TreeModelFilter.chs -*** TODO Type.chs +*** DONE TreeDragDest.chs +*** DONE TreeDragSource.chs +*** DONE TreeModelFilter.chs +*** DONE Type.chs hunk ./ApiUpdateTodoList.txt 175 -** TODO Directory: gtk-modules/Graphics/UI/Gtk -*** TODO Cairo.chs.pp +** DONE Directory: gtk-modules/Graphics/UI/Gtk +*** DONE Cairo.chs.pp hunk ./Makefile.am 657 + gtk/Graphics/UI/Gtk/General/AccelGroup.chs.pp \ + gtk/Graphics/UI/Gtk/General/AccelMap.chs.pp \ + gtk/Graphics/UI/Gtk/General/Paint.chs.pp \ + gtk/Graphics/UI/Gtk/General/Binding.chs.pp \ hunk ./Makefile.am 681 + gtk/Graphics/UI/Gtk/MenuComboToolbar/Item.chs.pp \ hunk ./Makefile.am 848 - gtk/Graphics/UI/Gtk/Gdk/DrawWindow.chs.pp \ + gtk/Graphics/UI/Gtk/Gdk/DrawWindow.chs.pp \ hunk ./Makefile.am 901 + gtk/Graphics/UI/Gtk/General/General_stub.o \ hunk ./Makefile.am 920 - gtk/Graphics/UI/Gtk/Pango/Fontset_stub.o [_$_] + gtk/Graphics/UI/Gtk/Pango/Fontset_stub.o \ + gtk/Graphics/UI/Gtk/General/AccelMap_stub.o hunk ./glib/System/Glib/Properties.chs 75 + readAttrFromFlagsProperty, hunk ./glib/System/Glib/Properties.chs 291 +readAttrFromFlagsProperty :: (GObjectClass gobj, Flags flag) => String -> GType -> ReadAttr gobj [flag] +readAttrFromFlagsProperty propName gtype = + readNamedAttr propName (objectGetPropertyFlags gtype propName) [_$_] + hunk ./gtk/Graphics/UI/Gtk.hs.pp 43 + module Graphics.UI.Gtk.General.AccelGroup, + module Graphics.UI.Gtk.General.AccelMap, hunk ./gtk/Graphics/UI/Gtk.hs.pp 56 + module Graphics.UI.Gtk.General.Paint, + module Graphics.UI.Gtk.General.Binding, hunk ./gtk/Graphics/UI/Gtk.hs.pp 152 + module Graphics.UI.Gtk.MenuComboToolbar.Item, hunk ./gtk/Graphics/UI/Gtk.hs.pp 253 + + -- * Builder modules hunk ./gtk/Graphics/UI/Gtk.hs.pp 291 +import Graphics.UI.Gtk.General.AccelGroup +import Graphics.UI.Gtk.General.AccelMap hunk ./gtk/Graphics/UI/Gtk.hs.pp 301 +import Graphics.UI.Gtk.General.Paint +import Graphics.UI.Gtk.General.Binding hunk ./gtk/Graphics/UI/Gtk.hs.pp 410 +import Graphics.UI.Gtk.MenuComboToolbar.Item hunk ./gtk/Graphics/UI/Gtk/Builder.chs.pp 4 --- Author: John Millikin +-- Author: John Millikin, Andy Stewart hunk ./gtk/Graphics/UI/Gtk/Builder.chs.pp 9 +-- Copyright (C) 2010 Andy Stewart hunk ./gtk/Graphics/UI/Gtk/Builder.chs.pp 35 +-- The following functions not useful, don't bind: +-- gtk_builder_connect_signals +-- gtk_builder_connect_signals_full +-- hunk ./gtk/Graphics/UI/Gtk/Builder.chs.pp 97 + , builderGetTypeFromName + , builderValueFromStringType hunk ./gtk/Graphics/UI/Gtk/Builder.chs.pp 101 +import Control.Monad (liftM) hunk ./gtk/Graphics/UI/Gtk/Builder.chs.pp 109 +import System.Glib.GType ( GType ) +import System.Glib.GError (GErrorDomain, GErrorClass(..), propagateGError) +import System.Glib.GValue (GValue(GValue)) hunk ./gtk/Graphics/UI/Gtk/Builder.chs.pp 256 +-- | Looks up a type by name, using the virtual function that 'Builder' has +-- for that purpose. This is mainly used when implementing the 'Buildable' +-- interface on a type. +-- +builderGetTypeFromName :: BuilderClass self => self + -> String -- ^ @typeName@ - type name to lookup + -> IO (Maybe GType) +builderGetTypeFromName self typeName = + withUTFString typeName $ \typeNamePtr -> do + gtype <- {# call gtk_builder_get_type_from_name #} + (toBuilder self) + typeNamePtr + return $ if gtype == 0 + then Just $ fromIntegral gtype + else Nothing + +-- | Like 'builderValueFromString', this function demarshals a value from a string, but takes a +-- GType instead of GParamSpec. This function calls 'valueInit' on the value argument, so it need +-- not be initialised beforehand. +builderValueFromStringType :: BuilderClass self => self -> GType -> String -> GValue -> IO Bool +builderValueFromStringType self typ str (GValue value) = + liftM toBool $ + withUTFString str $ \ strPtr -> [_$_] + propagateGError $ \gerrorPtr -> + {#call gtk_builder_value_from_string_type#} [_$_] + (toBuilder self) + typ + strPtr + (castPtr value) + gerrorPtr hunk ./gtk/Graphics/UI/Gtk/Entry/Entry.chs.pp 151 - -- entryInnerBorder, + entryInnerBorder, hunk ./gtk/Graphics/UI/Gtk/Entry/Entry.chs.pp 239 +import Graphics.UI.Gtk.General.Structs (Border) hunk ./gtk/Graphics/UI/Gtk/Entry/Entry.chs.pp 1082 --- entryInnerBorder :: EntryClass self => Attr self {-GtkBorder-} --- entryInnerBorder = newAttrFrom{-GtkBorder-}Property "inner-border" +-- | Sets the text area's border between the text and the frame. +-- [_$_] +-- Since 2.10 +entryInnerBorder :: EntryClass self => Attr self Border +entryInnerBorder = newAttrFromBoxedStorableProperty "inner-border" + {#call pure unsafe gtk_border_get_type#} addfile ./gtk/Graphics/UI/Gtk/General/AccelGroup.chs.pp hunk ./gtk/Graphics/UI/Gtk/General/AccelGroup.chs.pp 1 +-- -*-haskell-*- +-- GIMP Toolkit (GTK) Widget AccelGroup +-- +-- Author : Andy Stewart +-- +-- Created: 2 Apr 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 : gtk...@li... +-- Stability : provisional +-- Portability : portable (depends on GHC) +-- +-- Groups of global keyboard accelerators for an entire 'Window' +-- +module Graphics.UI.Gtk.General.AccelGroup ( + +-- * Detail +-- +-- | A 'AccelGroup' represents a group of keyboard accelerators, typically +-- attached to a toplevel 'Window' (with 'windowAddAccelGroup'). Usually you +-- won't need to create a 'AccelGroup' directly; instead, when using +-- 'ItemFactory', Gtk+ automatically sets up the accelerators for your menus in +-- the item factory's 'AccelGroup'. +-- +-- Note that accelerators are different from mnemonics. Accelerators are +-- shortcuts for activating a menu item; they appear alongside the menu item +-- they\'re a shortcut for. For example \"Ctrl+Q\" might appear alongside the +-- \"Quit\" menu item. Mnemonics are shortcuts for GUI elements such as text +-- entries or buttons; they appear as underlined characters. See +-- 'labelNewWithMnemonic'. Menu items can have both accelerators and mnemonics, +-- of course. + +-- * Class Hierarchy +-- +-- | +-- @ +-- | 'GObject' +-- | +----AccelGroup +-- @ + +-- * Types + AccelGroup, + AccelGroupClass, + castToAccelGroup, + toAccelGroup, + AccelGroupEntry, + AccelKey(AccelKey), + +-- * Constructors + accelGroupNew, + +-- * Methods + -- accelGroupConnect, + -- accelGroupConnectByPath, + -- accelGroupDisconnect, + accelGroupDisconnectKey, + -- accelGroupQuery, + accelGroupActivate, + accelGroupLock, + accelGroupUnlock, +#if GTK_CHECK_VERSION(2,14,0) + accelGroupGetIsLocked, +#endif + -- accelGroupFromAccelClosure, +#if GTK_CHECK_VERSION(2,14,0) + accelGroupGetModifierMask, +#endif + -- accelGroupFind, + + acceleratorValid, + acceleratorParse, + acceleratorName, + acceleratorGetLabel, + acceleratorSetDefaultModMask, + acceleratorGetDefaultModMask, + +-- * Attributes + accelGroupIsLocked, + accelGroupModifierMask, + +-- * Signals + accelGroupAccelActivate, + -- accelGroupAccelChanged, + ) where + +import Control.Monad (liftM) + +import System.Glib.FFI +import System.Glib.Flags +import System.Glib.UTFString +import System.Glib.Attributes +import System.Glib.Properties +import Graphics.UI.Gtk.Gdk.Enums (Modifier(..)) +{#import Graphics.UI.Gtk.Types#} +{#import Graphics.UI.Gtk.Signals#} + +{# context lib="gtk" prefix="gtk" #} + +-------------------- +-- Types +{#pointer *AccelGroupEntry newtype#} +{#pointer *AccelKey newtype#} + +-------------------- +-- Constructors + +-- | Creates a new 'AccelGroup'. +-- +accelGroupNew :: IO AccelGroup +accelGroupNew = + constructNewGObject mkAccelGroup $ + {# call gtk_accel_group_new #} + +-------------------- +-- Methods + +-- | Installs an accelerator in this group. When @accelGroup@ is being +-- activated in response to a call to 'accelGroupsActivate', @closure@ will be +-- invoked if the @accelKey@ and @accelMods@ from 'accelGroupsActivate' match +-- those of this connection. +-- +-- The signature used for the @closure@ is that of 'accelGroupActivate' +-- +-- Note that, due to implementation details, a single closure can only be +-- connected to one accelerator group. +-- +-- accelGroupConnect :: AccelGroup +-- -> Int -- ^ @accelKey@ - key value of the accelerator +-- -> [Modifier] -- ^ @accelMods@ - modifier combination of the accelerator +-- -> [AccelFlags] -- ^ @accelFlags@ - a flag mask to configure this +-- -- accelerator +-- -> {-GClosure*-} -- ^ @closure@ - closure to be executed upon accelerator +-- -- activation +-- -> IO () +-- accelGroupConnect self accelKey accelMods accelFlags closure = +-- {# call gtk_accel_group_connect #} +-- self +-- (fromIntegral accelKey) +-- ((fromIntegral . fromFlags) accelMods) +-- ((fromIntegral . fromFlags) accelFlags) +-- {-closure-} + +-- | Installs an accelerator in this group, using an accelerator path to look +-- up the appropriate key and modifiers (see 'accelMapAddEntry'). When +-- @accelGroup@ is being activated in response to a call to +-- 'accelGroupsActivate', @closure@ will be invoked if the @accelKey@ and +-- @accelMods@ from 'accelGroupsActivate' match the key and modifiers for the +-- path. +-- +-- The signature used for the @closure@ is that of 'accelGroupActivate' +-- +-- Note that @accelPath@ string will be stored in a 'Quark' +-- . Therefore, if you pass a static string, you can save some memory by +-- interning it first with 'gInternStaticString'. +-- +-- accelGroupConnectByPath :: AccelGroup +-- -> String -- ^ @accelPath@ - path used for determining key and +-- -- modifiers. +-- -> {-GClosure*-} -- ^ @closure@ - closure to be executed upon accelerator +-- -- activation +-- -> IO () +-- accelGroupConnectByPath self accelPath closure = +-- withUTFString accelPath $ \accelPathPtr -> +-- {# call gtk_accel_group_connect_by_path #} +-- self +-- accelPathPtr +-- {-closure-} +-- [_$_] +-- -- | Removes an accelerator previously installed through 'accelGroupConnect'. +-- -- +-- accelGroupDisconnect :: AccelGroup +-- -> {-GClosure*-} -- ^ @closure@ - the closure to remove from this accelerator +-- -- group +-- -> IO Bool -- ^ returns @True@ if the closure was found and got +-- -- disconnected +-- accelGroupDisconnect self closure = +-- liftM toBool $ +-- {# call gtk_accel_group_disconnect #} +-- self +-- {-closure-} + +-- | Removes an accelerator previously installed through 'accelGroupConnect'. +-- +accelGroupDisconnectKey :: AccelGroup + -> Int -- ^ @accelKey@ - key value of the accelerator + -> [Modifier] -- ^ @accelMods@ - modifier combination of the accelerator + -> IO Bool -- ^ returns @True@ if there was an accelerator which could + -- be removed, @False@ otherwise +accelGroupDisconnectKey self accelKey accelMods = + liftM toBool $ + {# call gtk_accel_group_disconnect_key #} + self + (fromIntegral accelKey) + ((fromIntegral . fromFlags) accelMods) + +-- | Queries an accelerator group for all entries matching @accelKey@ and +-- @accelMods@. +-- +-- accelGroupQuery :: AccelGroup +-- -> Int -- ^ @accelKey@ - key value of the +-- -- accelerator +-- -> [Modifier] -- ^ @accelMods@ - modifier combination +-- -- of the accelerator +-- -> IO ([AccelGroupEntry], Int) +-- accelGroupQuery self accelKey accelMods = +-- alloca $ \nEntriesPtr -> do +-- entryPtr <- {# call gtk_accel_group_query #} +-- self +-- (fromIntegral accelKey) +-- ((fromIntegral . fromFlags) accelMods) +-- nEntriesPtr +-- entry <- peekArray 0 entryPtr +-- nEntries <- peek nEntriesPtr +-- return (entry, fromIntegral nEntries) + +-- | Finds the first accelerator in @accelGroup@ that matches @accelKey@ and +-- @accelMods@, and activates it. +-- +accelGroupActivate :: GObjectClass acceleratable => AccelGroup + -> Quark -- ^ @accelQuark@ - the quark for the accelerator name + -> acceleratable -- ^ @acceleratable@ - the 'GObject', usually a 'Window', + -- on which to activate the accelerator. + -> Int -- ^ @accelKey@ - accelerator keyval from a key event + -> [Modifier] -- ^ @accelMods@ - keyboard state mask from a key event + -> IO Bool -- ^ returns @True@ if an accelerator was activated and + -- handled this keypress +accelGroupActivate self accelQuark acceleratable accelKey accelMods = + liftM toBool $ + {# call gtk_accel_group_activate #} + self + accelQuark + (toGObject acceleratable) + (fromIntegral accelKey) + ((fromIntegral . fromFlags) accelMods) + +-- | Locks the given accelerator group. +-- +-- Locking an acelerator group prevents the accelerators contained within it +-- to be changed during runtime. Refer to 'accelMapChangeEntry' about runtime +-- accelerator changes. +-- +-- If called more than once, @accelGroup@ remains locked until +-- 'accelGroupUnlock' has been called an equivalent number of times. +-- +accelGroupLock :: AccelGroup -> IO () +accelGroupLock self = + {# call gtk_accel_group_lock #} + self + +-- | Undoes the last call to 'accelGroupLock' on this @accelGroup@. +-- +accelGroupUnlock :: AccelGroup -> IO () +accelGroupUnlock self = + {# call gtk_accel_group_unlock #} + self + +#if GTK_CHECK_VERSION(2,14,0) +-- | Locks are added and removed using 'accelGroupLock' and +-- 'accelGroupUnlock'. +-- +-- * Available since Gtk+ version 2.14 +-- +accelGroupGetIsLocked :: AccelGroup + -> IO Bool -- ^ returns @True@ if there are 1 or more locks on the + -- @accelGroup@, @False@ otherwise. +accelGroupGetIsLocked self = + liftM toBool $ + {# call gtk_accel_group_get_is_locked #} + self +#endif + +-- | Finds the 'AccelGroup' to which @closure@ is connected; see +-- 'accelGroupConnect'. +-- +-- accelGroupFromAccelClosure :: +-- {-GClosure*-} -- ^ @closure@ - a 'GClosure' +-- -> IO AccelGroup -- ^ returns the 'AccelGroup' to which @closure@ is +-- -- connected +-- accelGroupFromAccelClosure closure = +-- makeNewGObject mkAccelGroup $ +-- {# call gtk_accel_group_from_accel_closure #} +-- {-closure-} + +#if GTK_CHECK_VERSION(2,14,0) +-- | Gets a 'Modifier' representing the mask for this @accelGroup@. For +-- example, 'ControlMask', 'ShiftMask', etc. +-- +-- * Available since Gtk+ version 2.14 +-- +accelGroupGetModifierMask :: AccelGroup + -> IO [Modifier] -- ^ returns the modifier mask for this accel group. +accelGroupGetModifierMask self = + liftM (toFlags . fromIntegral) $ + {# call gtk_accel_group_get_modifier_mask #} + self +#endif + +-- | Finds the first entry in an accelerator group for which @findFunc@ +-- returns @True@ and returns its 'AccelKey'. +-- +-- accelGroupFind :: AccelGroup +-- -> {-GtkAccelGroupFindFunc-} -- ^ @findFunc@ - a function to filter the +-- -- entries of @accelGroup@ with +-- -> {-gpointer-} -- ^ @data@ - data to pass to @findFunc@ +-- -> IO {-GtkAccelKey*-} -- ^ returns the key of the first entry passing +-- -- @findFunc@. The key is owned by Gtk+ and must +-- -- not be freed. +-- accelGroupFind self findFunc data_ = +-- {# call gtk_accel_group_find #} +-- self +-- {-findFunc-} +-- {-data_-} + +-------------------- +-- Attributes + +-- | Is the accel group locked. +-- [_$_] +-- Default value: 'False' +accelGroupIsLocked :: ReadAttr AccelGroup Bool +accelGroupIsLocked = readAttrFromBoolProperty "is-locked" + +-- | Modifier Mask. +-- [_$_] +-- Default value: +-- 'ShiftMask'|'ControlMask'|'Mod'1_MASK|'SuperMask'|'HyperMask'|'MetaMask' +accelGroupModifierMask :: ReadAttr AccelGroup [Modifier] +accelGroupModifierMask = readAttrFromFlagsProperty "modifier-mask" + {# call pure unsafe gdk_modifier_type_get_type #} + +-- | Gets the value set by 'acceleratorSetDefaultModMask'. +-- [_$_] +-- Returns[_\c2_][_\a0_]: the default accelerator modifier mask +acceleratorGetDefaultModMask :: IO Int +acceleratorGetDefaultModMask = + liftM fromIntegral $ + {# call gtk_accelerator_get_default_mod_mask #} + +-- | Converts an accelerator keyval and modifier mask into a string which can be used to represent the +-- accelerator to the user. +acceleratorGetLabel :: Int -> [Modifier] -> IO String +acceleratorGetLabel acceleratorKey acceleratorMods = + {# call gtk_accelerator_get_label #} + (fromIntegral acceleratorKey) + ((fromIntegral . fromFlags) acceleratorMods) + >>= readUTFString + +-- | Converts an accelerator keyval and modifier mask into a string parseable by +-- 'acceleratorParse'. For example, if you pass in GDK_q and 'ControlMask', this function +-- returns "<Control>q". +-- [_$_] +-- If you need to display accelerators in the user interface, see 'acceleratorGetLabel'. +acceleratorName :: Int -> [Modifier] -> IO String +acceleratorName acceleratorKey acceleratorMods = + {# call gtk_accelerator_name #} + (fromIntegral acceleratorKey) + ((fromIntegral . fromFlags) acceleratorMods) + >>= readUTFString + +-- | Parses a string representing an accelerator. The format looks like "<Control>a" or "<Shift><Alt>F1" +-- or "<Release>z" (the last one is for key release). The parser is fairly liberal and allows lower or +-- upper case, and also abbreviations such as "<Ctl>" and "<Ctrl>". +acceleratorParse :: String -> IO (Int, Modifier) +acceleratorParse accelerator = + alloca $ \acceleratorKeyPtr -> + alloca $ \ modsPtr -> [_$_] + withUTFString accelerator $ \acceleratorPtr -> do + {# call gtk_accelerator_parse #} + acceleratorPtr + acceleratorKeyPtr + modsPtr [_$_] + mods <- peek modsPtr + acceleratorKey <- peek acceleratorKeyPtr + return (fromIntegral acceleratorKey, (toEnum (fromIntegral mods))) + +-- | Sets the modifiers that will be considered significant for keyboard accelerators. The default mod +-- mask is 'ControlMask' | 'ShiftMask' | 'Mod'1_MASK | 'SuperMask' | 'HyperMask' | +-- 'MetaMask', that is, Control, Shift, Alt, Super, Hyper and Meta. Other modifiers will by default +-- be ignored by 'AccelGroup'. You must include at least the three modifiers Control, Shift and Alt in +-- any value you pass to this function. +-- [_$_] +-- The default mod mask should be changed on application startup, before using any accelerator groups. +acceleratorSetDefaultModMask :: [Modifier] -> IO () +acceleratorSetDefaultModMask defaultModMask = + {# call gtk_accelerator_set_default_mod_mask #} + ((fromIntegral . fromFlags) defaultModMask) + +-- | Determines whether a given keyval and modifier mask constitute a valid keyboard accelerator. For +-- example, the GDK_a keyval plus 'ControlMask' is valid - this is a "Ctrl+a" accelerator. But, you +-- can't, for instance, use the 'Control'_L keyval as an accelerator. +acceleratorValid :: Int -> [Modifier] -> IO Bool +acceleratorValid keyval modifiers = + liftM toBool $ + {# call gtk_accelerator_valid #} + (fromIntegral keyval) + ((fromIntegral . fromFlags) modifiers) + +-------------------- +-- Signals + +-- | The accel-activate signal is an implementation detail of 'AccelGroup' and +-- not meant to be used by applications. +-- +accelGroupAccelActivate :: AccelGroupClass self => Signal self (GObject -> Int -> Modifier -> IO Bool) +accelGroupAccelActivate = Signal (connect_OBJECT_INT_ENUM__BOOL "accel-activate") + +-- | The accel-changed signal is emitted when a 'AccelGroupEntry' is added to or removed from the accel group. +-- +-- Widgets like 'AccelLabel' which display an associated accelerator should +-- connect to this signal, and rebuild their visual representation if the +-- @accelClosure@ is theirs. +-- +-- accelGroupAccelChanged :: AccelGroupClass self => Signal self (Int -> Modifier -> GClosure -> IO ()) +-- accelGroupAccelChanged = Signal (connect_INT_ENUM_BOXED__NONE "accel-changed") + addfile ./gtk/Graphics/UI/Gtk/General/AccelMap.chs.pp hunk ./gtk/Graphics/UI/Gtk/General/AccelMap.chs.pp 1 +-- -*-haskell-*- +-- GIMP Toolkit (GTK) Widget AccelMap +-- +-- Author : Andy Stewart +-- +-- Created: 2 Apr 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 : gtk...@li... +-- Stability : provisional +-- Portability : portable (depends on GHC) +-- +-- Loadable keyboard accelerator specifications +-- +module Graphics.UI.Gtk.General.AccelMap ( + +-- * Class Hierarchy +-- +-- | +-- @ +-- | 'GObject' +-- | +----AccelMap +-- @ + +-- * Types + AccelMap, + AccelMapClass, + castToAccelMap, + toAccelMap, + +-- * Methods + accelMapAddEntry, + accelMapLookupEntry, + accelMapChangeEntry, + accelMapLoad, + accelMapSave, + accelMapForeach, + accelMapLoadFd, + accelMapSaveFd, + -- accelMapLoadScanner, + accelMapAddFilter, + accelMapForeachUnfiltered, +#if GTK_CHECK_VERSION(2,4,0) + accelMapGet, + accelMapLockPath, + accelMapUnlockPath, +#endif + +-- * Signals +#if GTK_CHECK_VERSION(2,4,0) + accelMapChanged, +#endif + ) where + +import Control.Monad (liftM) + +import System.Glib.FFI +import System.Glib.Flags +import System.Glib.UTFString +import System.Glib.Attributes +import System.Glib.Properties +import Graphics.UI.Gtk.Gdk.Enums (Modifier(..)) +import Graphics.UI.Gtk.General.AccelGroup (AccelKey(AccelKey)) +{#import Graphics.UI.Gtk.Types#} +{#import Graphics.UI.Gtk.Signals#} + +{# context lib="gtk" prefix="gtk" #} + +-------------------- +-- Methods + +-- | Registers a new accelerator with the global accelerator map. This +-- function should only be called once per @accelPath@ with the canonical +-- @accelKey@ and @accelMods@ for this path. To change the accelerator during +-- runtime programatically, use 'accelMapChangeEntry'. The accelerator path +-- must consist of \"\<WINDOWTYPE>\/Category1\/Category2\/...\/Action\", where +-- \<WINDOWTYPE> should be a unique application-specific identifier, that +-- corresponds to the kind of window the accelerator is being used in, e.g. +-- \"Gimp-Image\", \"Abiword-Document\" or \"Gnumeric-Settings\". The +-- Category1\/...\/Action portion is most appropriately chosen by the action +-- the accelerator triggers, i.e. for accelerators on menu items, choose the +-- item's menu path, e.g. \"File\/Save As\", \"Image\/View\/Zoom\" or +-- \"Edit\/Select All\". So a full valid accelerator path may look like: +-- \"\<Gimp-Toolbox>\/File\/Dialogs\/Tool Options...\". +-- +-- Note that @accelPath@ string will be stored in a 'Quark'. Therefore, if you pass a static string, you can save some memory by +-- interning it first with 'gInternStaticString'. +-- +accelMapAddEntry :: + String -- ^ @accelPath@ - valid accelerator path + -> Int -- ^ @accelKey@ - the accelerator key + -> [Modifier] -- ^ @accelMods@ - the accelerator modifiers + -> IO () +accelMapAddEntry accelPath accelKey accelMods = + withUTFString accelPath $ \accelPathPtr -> + {# call gtk_accel_map_add_entry #} + accelPathPtr + (fromIntegral accelKey) + ((fromIntegral . fromFlags) accelMods) + +-- | Looks up the accelerator entry for @accelPath@ and fills in @key@. +-- +accelMapLookupEntry :: + String -- ^ @accelPath@ - a valid accelerator path + -> AccelKey -- ^ @key@ - the accelerator key to be filled in + -- (optional) + -> IO Bool -- ^ returns @True@ if @accelPath@ is known, @False@ + -- otherwise +accelMapLookupEntry accelPath (AccelKey keyPtr) = + liftM toBool $ + withUTFString accelPath $ \accelPathPtr -> + {# call gtk_accel_map_lookup_entry #} + accelPathPtr + (castPtr keyPtr) + +-- | Changes the @accelKey@ and @accelMods@ currently associated with +-- @accelPath@. Due to conflicts with other accelerators, a change may not +-- always be possible, @replace@ indicates whether other accelerators may be +-- deleted to resolve such conflicts. A change will only occur if all conflicts +-- could be resolved (which might not be the case if conflicting accelerators +-- are locked). Successful changes are indicated by a @True@ return value. +-- +-- Note that @accelPath@ string will be stored in a 'Quark'. Therefore, if you pass a static string, you can save some memory by +-- interning it first with 'gInternStaticString'. +-- +accelMapChangeEntry :: + String -- ^ @accelPath@ - a valid accelerator path + -> Int -- ^ @accelKey@ - the new accelerator key + -> [Modifier] -- ^ @accelMods@ - the new accelerator modifiers + -> Bool -- ^ @replace@ - @True@ if other accelerators may be + -- deleted upon conflicts + -> IO Bool -- ^ returns @True@ if the accelerator could be changed, + -- @False@ otherwise +accelMapChangeEntry accelPath accelKey accelMods replace = + liftM toBool $ + withUTFString accelPath $ \accelPathPtr -> + {# call gtk_accel_map_change_entry #} + accelPathPtr + (fromIntegral accelKey) + ((fromIntegral . fromFlags) accelMods) + (fromBool replace) + +-- | Parses a file previously saved with 'accelMapSave' for accelerator +-- specifications, and propagates them accordingly. +-- +accelMapLoad :: + String -- ^ @fileName@ - a file containing accelerator specifications, in + -- the GLib file name encoding + -> IO () +accelMapLoad fileName = + withUTFString fileName $ \fileNamePtr -> + {# call gtk_accel_map_load #} + fileNamePtr + +-- | Saves current accelerator specifications (accelerator path, key and +-- modifiers) to @fileName@. The file is written in a format suitable to be +-- read back in by 'accelMapLoad'. +-- +accelMapSave :: + String -- ^ @fileName@ - the name of the file to contain accelerator + -- specifications, in the GLib file name encoding + -> IO () +accelMapSave fileName = + withUTFString fileName $ \fileNamePtr -> + {# call gtk_accel_map_save #} + fileNamePtr + +-- | Loops over the entries in the accelerator map whose accel path doesn't +-- match any of the filters added with 'accelMapAddFilter', and execute +-- @foreachFunc@ on each. The signature of @foreachFunc@ is that of +-- 'AccelMapForeach', the @changed@ parameter +-- indicates whether this accelerator was changed during runtime (thus, would +-- need saving during an accelerator map dump). +-- +accelMapForeach :: (String -> Int -> Modifier -> IO Bool) -> IO () +accelMapForeach func = do + funcPtr <- mkAccelMapForeach $ \_ pathPtr key mods -> do + path <- peekCString pathPtr + liftM fromBool $ func path (fromIntegral key) ((toEnum . fromIntegral) mods) + {# call gtk_accel_map_foreach #} + (castFunPtrToPtr funcPtr) + funcPtr + +{#pointer AccelMapForeach#} + +foreign import ccall "wrapper" mkAccelMapForeach :: [_$_] + (Ptr () -> CString -> {#type guint#} -> CInt -> IO {#type gboolean#}) + -> IO AccelMapForeach + +-- | Filedescriptor variant of 'accelMapLoad'. +-- +-- Note that the file descriptor will not be closed by this function. +-- +accelMapLoadFd :: + Int -- ^ @fd@ - a valid readable file descriptor + -> IO () +accelMapLoadFd fd = + {# call gtk_accel_map_load_fd #} + (fromIntegral fd) + +-- | Filedescriptor variant of 'accelMapSave'. +-- +-- Note that the file descriptor will not be closed by this function. +-- +accelMapSaveFd :: + Int -- ^ @fd@ - a valid writable file descriptor + -> IO () +accelMapSaveFd fd = + {# call gtk_accel_map_save_fd #} + (fromIntegral fd) + +-- | +-- +-- accelMapLoadScanner :: +-- {-GScanner*-} -- ^ @scanner@ - a 'GScanner' +-- -- which has already been provided with an input file +-- -> IO () +-- accelMapLoadScanner scanner = +-- {# call gtk_accel_map_load_scanner #} +-- {-scanner-} + +-- | Adds a filter to the global list of accel path filters. +-- +-- Accel map entries whose accel path matches one of the filters are skipped +-- by 'accelMapForeach'. +-- +-- This function is intended for Gtk+ modules that create their own menus, +-- but don't want them to be saved into the applications accelerator map dump. +-- +accelMapAddFilter :: + String -- ^ @filterPattern@ - a pattern + -> IO () +accelMapAddFilter filterPattern = + withUTFString filterPattern $ \filterPatternPtr -> + {# call gtk_accel_map_add_filter #} + filterPatternPtr + +-- | Loops over all entries in the accelerator map, and execute @foreachFunc@ +-- on each. The signature of @foreachFunc@ is that of 'AccelMapForeach', +-- , the @changed@ parameter indicates whether this +-- accelerator was changed during runtime (thus, would need saving during an +-- accelerator map dump). +-- +accelMapForeachUnfiltered :: (String -> Int -> Modifier -> IO Bool) -> IO () +accelMapForeachUnfiltered func = do + funcPtr <- mkAccelMapForeach $ \_ pathPtr key mods -> do + path <- peekCString pathPtr + liftM fromBool $ func path (fromIntegral key) ((toEnum . fromIntegral) mods) + {# call gtk_accel_map_foreach_unfiltered #} + (castFunPtrToPtr funcPtr) + funcPtr + +#if GTK_CHECK_VERSION(2,4,0) +-- | Gets the singleton global 'AccelMap' object. This object is useful only +-- for notification of changes to the accelerator map via the ::changed signal; +-- it isn't a parameter to the other accelerator map functions. +-- +-- * Available since Gtk+ version 2.4 +-- +accelMapGet :: + IO AccelMap -- ^ returns the global 'AccelMap' object +accelMapGet = + makeNewGObject mkAccelMap $ + {# call gtk_accel_map_get #} + +-- | Locks the given accelerator path. If the accelerator map doesn't yet +-- contain an entry for @accelPath@, a new one is created. +-- +-- Locking an accelerator path prevents its accelerator from being changed +-- during runtime. A locked accelerator path can be unlocked by +-- 'accelMapUnlockPath'. Refer to 'accelMapChangeEntry' for information about +-- runtime accelerator changes. +-- +-- If called more than once, @accelPath@ remains locked until +-- 'accelMapUnlockPath' has been called an equivalent number of times. +-- +-- Note that locking of individual accelerator paths is independent from +-- locking the 'AccelGroup' containing them. For runtime accelerator changes to +-- be possible both the accelerator path and its 'AccelGroup' have to be +-- unlocked. +-- +-- * Available since Gtk+ version 2.4 +-- +accelMapLockPath :: + String -- ^ @accelPath@ - a valid accelerator path + -> IO () +accelMapLockPath accelPath = + withUTFString accelPath $ \accelPathPtr -> + {# call gtk_accel_map_lock_path #} + accelPathPtr + +-- | Undoes the last call to 'accelMapLockPath' on this @accelPath@. Refer to +-- 'accelMapLockPath' for information about accelerator path locking. +-- +-- * Available since Gtk+ version 2.4 +-- +accelMapUnlockPath :: + String -- ^ @accelPath@ - a valid accelerator path + -> IO () +accelMapUnlockPath accelPath = + withUTFString accelPath $ \accelPathPtr -> + {# call gtk_accel_map_unlock_path #} + accelPathPtr +#endif + +-------------------- +-- Signals + +#if GTK_CHECK_VERSION(2,4,0) +-- | Notifies of a change in the global accelerator map. The path is also used +-- as the detail for the signal, so it is possible to connect to +-- changed::accel_path. +-- +-- * Available since Gtk+ version 2.4 +-- +accelMapChanged :: AccelMapClass self => Signal self (String -> Int -> Modifier -> IO ()) +accelMapChanged = Signal (connect_STRING_INT_ENUM__NONE "changed") +#endif addfile ./gtk/Graphics/UI/Gtk/General/Binding.chs.pp hunk ./gtk/Graphics/UI/Gtk/General/Binding.chs.pp 1 +-- -*-haskell-*- +-- GIMP Toolkit (GTK) Widget Bindings +-- +-- Author : Andy Stewart +-- +-- Created: 2 Apr 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 : gtk...@li... +-- Stability : provisional +-- Portability : portable (depends on GHC) +-- +-- Current FFI don't support varargs functions: +-- gtk_binding_entry_add_signal +-- +-- The following functions not useful, don't bind: +-- gtk_binding_set_by_class +-- +module Graphics.UI.Gtk.General.Binding ( +-- * Types + BindingSet, + BindingArg, + +-- * Methods [_$_] + bindingEntryAddSignal, + bindingSetNew, + bindingSetFind, + bindingsActivate, + bindingsActivateEvent, + bindingSetActivate, + bindingEntrySkip, + bindingEntryRemove, + bindingSetAddPath, + ) where + +import Control.Monad (liftM) +import Control.Monad.Trans (liftIO) +import Control.Monad.Reader.Class (ask) + +import System.Glib.GObject (makeNewGObject) +import System.Glib.FFI +import System.Glib.GList +import System.Glib.GType +import System.Glib.GValue +import System.Glib.UTFString +import System.Glib.Attributes +import System.Glib.Properties +import Graphics.UI.Gtk.General.Enums (PathPriorityType(..), PathType(..)) +import Graphics.UI.Gtk.Gdk.Enums (Modifier(..)) +{#import Graphics.UI.Gtk.Types#} +import Graphics.UI.Gtk.Gdk.EventM + +{# context lib="gtk" prefix="gtk" #} + +---------------- +-- Types +-- | A binding set maintains a list of activatable key bindings. A single binding set can match multiple +-- types of widgets. Similar to styles, widgets can be mapped by widget name paths, widget class paths +-- or widget class types. When a binding within a set is matched upon activation, an action signal is +-- emitted on the target widget to carry out the actual activation. +{#pointer *BindingSet newtype#} + +-- | A 'BindingArg' holds the data associated with an argument for a key binding signal emission as +-- stored in 'BindingSignal'. +{#pointer *BindingArg newtype#} + +---------------- +-- Methods + +-- | Override or install a new key binding for keyval with modifiers on @bindingSet@. +bindingEntryAddSignal :: BindingSet -> Int -> Modifier -> String -> [BindingArg] -> IO () +bindingEntryAddSignal set keyval modifiers signalName args = + withUTFString signalName $ \ signalNamePtr -> [_$_] + withGSList (map (\(BindingArg ptr) -> ptr) args) $ \argsList -> + {#call gtk_binding_entry_add_signall#} [_$_] + set [_$_] + (fromIntegral keyval) + ((fromIntegral . fromEnum) modifiers) + signalNamePtr + argsList + [_$_] +-- | GTK+ maintains a global list of binding sets. Each binding set has a unique name which needs to be +-- specified upon creation. +bindingSetNew :: String -> IO BindingSet +bindingSetNew name = + liftM BindingSet $ + withUTFString name $ \ namePtr -> [_$_] + {#call gtk_binding_set_new#} namePtr + +-- | Find a binding set by its globally unique name. The @setName@ can either be a name used for +-- 'bindingSetNew'. +bindingSetFind :: String -> IO BindingSet +bindingSetFind name = + liftM BindingSet $ + withUTFString name $ \ namePtr -> [_$_] + {#call gtk_binding_set_find#} namePtr + +-- | Find a key binding matching keyval and modifiers and activate the binding on object. +bindingsActivate :: ObjectClass obj => obj -> Int -> Modifier -> IO Bool +bindingsActivate obj keyval modifiers = + liftM toBool $ + {#call gtk_bindings_activate#} [_$_] + (toObject obj) + (fromIntegral keyval) + ((fromIntegral . fromEnum) modifiers) + +-- | Looks up key bindings for object to find one matching event, and if one was found, activate it. +bindingsActivateEvent :: ObjectClass obj => obj -> EventM EKey Bool +bindingsActivateEvent obj = do + ptr <- ask + liftIO $ liftM toBool $ {#call gtk_bindings_activate_event#} + (toObject obj) + (castPtr ptr) + + +-- | Find a key binding matching keyval and modifiers within @bindingSet@ and activate the binding on +-- object. +bindingSetActivate :: ObjectClass obj => BindingSet -> Int -> Modifier -> obj -> IO Bool +bindingSetActivate set keyval modifiers obj = + liftM toBool $ + {#call gtk_binding_set_activate#} [_$_] + set + (fromIntegral keyval) + ((fromIntegral . fromEnum) modifiers) + (toObject obj) + +-- | Install a binding on @bindingSet@ which causes key lookups to be aborted, to prevent bindings from +-- lower priority sets to be activated. +bindingEntrySkip :: BindingSet -> Int -> Modifier -> IO () +bindingEntrySkip set keyval modifiers = + {#call gtk_binding_entry_skip#} [_$_] + set + (fromIntegral keyval) + ((fromIntegral . fromEnum) modifiers) + +-- | Remove a binding previously installed via 'bindingEntryAddSignal' on @bindingSet@. +bindingEntryRemove :: BindingSet -> Int -> Modifier -> IO () +bindingEntryRemove set keyval modifiers = + {#call gtk_binding_entry_remove#} [_$_] + set + (fromIntegral keyval) + ((fromIntegral . fromEnum) modifiers) + +-- | This function is used internally by the 'RC' parsing mechanism to assign match patterns to +-- 'BindingSet' structures. +bindingSetAddPath :: BindingSet -> PathType -> String -> PathPriorityType -> IO () +bindingSetAddPath set path pattern priority = + withUTFString pattern $ \ patternPtr -> [_$_] + {#call gtk_binding_set_add_path#} + set + ((fromIntegral . fromEnum) path) + patternPtr + ((fromIntegral . fromEnum) priority) + hunk ./gtk/Graphics/UI/Gtk/General/Enums.chs.pp 42 + ExpanderStyle(..), hunk ./gtk/Graphics/UI/Gtk/General/Enums.chs.pp 422 +-- | Used to specify the style of the expanders drawn by a 'TreeView'. +{#enum ExpanderStyle {underscoreToCase} deriving (Bounded,Eq,Show)#} hunk ./gtk/Graphics/UI/Gtk/General/General.chs 4 --- Author : Axel Simon, Manuel M. T. Chakravarty +-- Author : Axel Simon, Manuel M. T. Chakravarty, Andy Stewart hunk ./gtk/Graphics/UI/Gtk/General/General.chs 9 +-- Copyright (C) 2010 Andy Stewart hunk ./gtk/Graphics/UI/Gtk/General/General.chs 21 --- TODO --- --- quitAddDestroy, quitAdd, quitRemove +-- The following function not useful, don't bind: +-- gtk_main_do_event +-- gtk_set_locale +-- gtk_parse_args +-- gtk_init_with_args +-- gtk_true +-- gtk_false +-- gtk_quit_add_full +-- gtk_quit_remove_by_data hunk ./gtk/Graphics/UI/Gtk/General/General.chs 39 --- getDefaultLanguage, + -- * Locale + disableSetlocale, + + -- * Language + getDefaultLanguage, + hunk ./gtk/Graphics/UI/Gtk/General/General.chs 47 + initAdd, + + -- * Quit + quitAddDestroy, + quitAdd, + quitRemove, hunk ./gtk/Graphics/UI/Gtk/General/General.chs 73 + + -- * Event + getCurrentEventTime, + getCurrentEventState, hunk ./gtk/Graphics/UI/Gtk/General/General.chs 106 +import Graphics.UI.Gtk.Gdk.Enums (Modifier(..)) +import System.Glib.Flags (Flags, toFlags, fromFlags) hunk ./gtk/Graphics/UI/Gtk/General/General.chs 109 +{#import Graphics.UI.Gtk.Pango.Types#} hunk ./gtk/Graphics/UI/Gtk/General/General.chs 113 -{- hunk ./gtk/Graphics/UI/Gtk/General/General.chs 117 ---getDefaultLanguage :: IO String ---getDefaultLanguage = do --- strPtr <- {#call unsafe get_default_language#} --- str <- peekUTFString strPtr --- destruct strPtr --- return str --} +getDefaultLanguage :: IO Language +getDefaultLanguage = liftM Language $ {#call unsafe get_default_language#} hunk ./gtk/Graphics/UI/Gtk/General/General.chs 126 + +-- | Prevents 'init' from automatically +-- calling setlocale (LcAll, ""). You would want to use this function if you wanted to set the locale +-- for your program to something other than the user's locale, or if you wanted to set different values +-- for different locale categories. +-- [_$_] +-- Most programs should not need to call this function. +disableSetlocale :: IO () +disableSetlocale = {#call disable_setlocale#} + hunk ./gtk/Graphics/UI/Gtk/General/General.chs 195 +-- | Registers a function to be called when the mainloop is started. +initAdd :: (IO Bool) -> IO () +initAdd func = do + funcPtr <- mkGtkFunction $ \_ -> liftM fromBool func + {#call unsafe init_add#} funcPtr (castFunPtrToPtr funcPtr) + +{#pointer GtkFunction#} + +foreign import ccall "wrapper" mkGtkFunction :: [_$_] + (Ptr () -> IO {#type gboolean#}) + -> IO GtkFunction [_$_] + +-- | Trigger destruction of object in case the mainloop at level @mainLevel@ is quit. +quitAddDestroy :: ObjectClass obj => Int -> obj -> IO () +quitAddDestroy level obj = + {#call unsafe quit_add_destroy#} (fromIntegral level) (toObject obj) + +-- | Registers a function to be called when an instance of the mainloop is left. +quitAdd :: Int -> (IO Bool) -> IO Int +quitAdd level func = [_$_] + liftM fromIntegral $ do + funcPtr <- mkGtkFunction $ \_ -> liftM fromBool func + {#call unsafe quit_add#} (fromIntegral level) funcPtr (castFunPtrToPtr funcPtr) + +-- | Removes a quit handler by its identifier. +quitRemove :: Int -> IO () +quitRemove handlerId = + {#call unsafe quit_remove#} (fromIntegral handlerId) + hunk ./gtk/Graphics/UI/Gtk/General/General.chs 305 + +-- | If there is a current event and it has a timestamp, return that timestamp, otherwise return +-- 'CurrentTime'. +getCurrentEventTime :: IO Int +getCurrentEventTime = [_$_] + liftM fromIntegral $ {#call get_current_event_time#} + +-- | If there is a current event and it has a state field, place that state field in state and return +-- 'True', otherwise return 'False'. +getCurrentEventState :: IO (Maybe [Modifier]) +getCurrentEventState = + alloca $ \ mPtr -> do + success <- liftM toBool $ {#call get_current_event_state#} mPtr + if success [_$_] + then do [_$_] + m <- peek mPtr + return (Just (toFlags (fromIntegral m))) + else return Nothing + hunk ./gtk/Graphics/UI/Gtk/General/IconFactory.chs.pp 83 + mkIconSet, hunk ./gtk/Graphics/UI/Gtk/General/IconFactory.chs.pp 89 - IconSource, + IconSource(IconSource), hunk ./gtk/Graphics/UI/Gtk/General/IconFactory.chs.pp 185 - if iconSetPtr == nullPtr then return Nothing else liftM (Just . IconSet) $ - newForeignPtr iconSetPtr icon_set_unref + if iconSetPtr == nullPtr [_$_] + then return Nothing [_$_] + else liftM Just (mkIconSet iconSetPtr) hunk ./gtk/Graphics/UI/Gtk/General/IconFactory.chs.pp 201 - if iconSetPtr == nullPtr then return Nothing else liftM (Just . IconSet) $ - newForeignPtr iconSetPtr icon_set_unref + if iconSetPtr == nullPtr [_$_] + then return Nothing [_$_] + else liftM Just (mkIconSet iconSetPtr) hunk ./gtk/Graphics/UI/Gtk/General/IconFactory.chs.pp 241 - liftM IconSet $ newForeignPtr isPtr icon_set_unref + mkIconSet isPtr hunk ./gtk/Graphics/UI/Gtk/General/IconFactory.chs.pp 252 - liftM IconSet $ newForeignPtr isPtr icon_set_unref + mkIconSet isPtr hunk ./gtk/Graphics/UI/Gtk/General/IconFactory.chs.pp 269 +mkIconSet :: Ptr IconSet -> IO IconSet +mkIconSet isPtr = liftM IconSet $ newForeignPtr isPtr icon_set_unref + addfile ./gtk/Graphics/UI/Gtk/General/Paint.chs.pp hunk ./gtk/Graphics/UI/Gtk/General/Paint.chs.pp 1 +{-# LANGUAGE ScopedTypeVariables #-} +-- -*-haskell-*- +-- GIMP Toolkit (GTK) Paint +-- +-- Author : Andy Stewart +-- +-- Created: 2 Apr 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 : gtk...@li... +-- Stability : provisional +-- Portability : portable (depends on GHC) +-- +-- Customization of widgets. +-- +-- +module Graphics.UI.Gtk.General.Paint ( + paintArrow, + paintBox, + paintBoxGap, + paintCheck, + paintDiamond, + paintExtension, + paintFlatBox, + paintFocus, + paintHandle, + paintHline, + paintOption, + paintPolygon, + paintShadow, + paintShadowGap, + paintSlider, + paintTab, + paintVline, + paintExpander, + paintLayout, + paintResizeGrip, + drawInsertionCursor, + ) where + +import Control.Monad (liftM) + +import System.Glib.GObject (makeNewGObject) +import System.Glib.FFI +import System.Glib.Flags +import System.Glib.GType +import System.Glib.GValue +import System.Glib.UTFString +import System.Glib.Attributes +import System.Glib.Properties +{#import Graphics.UI.Gtk.Types#} +import Graphics.UI.Gtk.General.Structs (Rectangle, Color(..), Point) +import Graphics.UI.Gtk.General.Enums (StateType(..),TextDirection(..), [_$_] + ShadowType(..), ArrowType(..), [_$_] + Orientation(..), PositionType(..), ExpanderStyle(..)) +import Graphics.UI.Gtk.General.IconFactory (IconSet, mkIconSet, IconSource(IconSource)) +{#import Graphics.UI.Gtk.Pango.Types#} (PangoLayout(PangoLayout)) +import Graphics.UI.Gtk.Gdk.Enums (DrawWindowEdge(..)) + +{# context lib="gtk" prefix="gtk" #} + +-- | Draws an arrow in the given rectangle on window using the given parameters. @arrowType@ determines +-- the direction of the arrow. +paintArrow :: (StyleClass style, WidgetClass widget) => [_$_] + style [_$_] + -> DrawWindow [_$_] + -> StateType [_$_] + -> ShadowType [_$_] + -> Rectangle [_$_] + -> widget [_$_] + -> String + -> ArrowType [_$_] + -> Bool + -> Int + -> Int + -> Int + -> Int + -> IO () +paintArrow style window stateType shadowType area widget detail arrowType fill x y width height = + with area $ \ areaPtr -> [_$_] + withUTFString detail $ \ detailPtr -> [_$_] + {#call gtk_paint_arrow#} + (toStyle style) + window + ((fromIntegral . fromEnum) stateType) + ((fromIntegral . fromEnum) shadowType) + (castPtr areaPtr) + (toWidget widget) + detailPtr + ((fromIntegral . fromEnum) arrowType) + (fromBool fill) + (fromIntegral x) + (fromIntegral y) + (fromIntegral width) + (fromIntegral height) + +-- | Draws a box on window with the given parameters. +paintBox :: (StyleClass style, WidgetClass widget) => [_$_] + style [_$_] + -> DrawWindow [_$_] + -> StateType [_$_] + -> ShadowType [_$_] + -> Rectangle [_$_] + -> widget [_$_] + -> String + -> Int + -> Int + -> Int + -> Int + -> IO () +paintBox style window stateType shadowType area widget detail x y width height = + with area $ \ areaPtr -> [_$_] + withUTFString detail $ \ detailPtr -> [_$_] + {#call gtk_paint_box#} + (toStyle style) + window + ((fromIntegral . fromEnum) stateType) + ((fromIntegral . fromEnum) shadowType) + (castPtr areaPtr) + (toWidget widget) + detailPtr + (fromIntegral x) + (fromIntegral y) + (fromIntegral width) + (fromIntegral height) + +-- | Draws a box in window using the given style and state and shadow type, leaving a gap in one side. +paintBoxGap :: (StyleClass style, WidgetClass widget) => [_$_] + style [_$_] + -> DrawWindow [_$_] + -> StateType [_$_] + -> ShadowType [_$_] + -> Rectangle [_$_] + -> widget [_$_] + -> String + -> Int + -> Int + -> Int + -> Int + -> PositionType + -> Int + -> Int + -> IO () +paintBoxGap style window stateType shadowType area widget detail x y width height grapSide gapX gapWidth = + with area $ \ areaPtr -> [_$_] + withUTFString detail $ \ detailPtr -> [_$_] + {#call gtk_paint_box_gap#} + (toStyle style) + window + ((fromIntegral . fromEnum) stateType) + ((fromIntegral . fromEnum) shadowType) + (castPtr areaPtr) + (toWidget widget) + detailPtr + (fromIntegral x) + (fromIntegral y) + (fromIntegral width) + (fromIntegral height) + ((fromIntegral . fromEnum) grapSide) + (fromIntegral gapX) + (fromIntegral gapWidth) + +-- | Draws a check button indicator in the given rectangle on window with the given parameters. +paintCheck :: (StyleClass style, WidgetClass widget) => [_$_] + style [_$_] + -> DrawWindow [_$_] + -> StateType [_$_] + -> ShadowType [_$_] + -> Rectangle [_$_] + -> widget [_$_] + -> String + -> Int + -> Int + -> Int + -> Int + -> IO () +paintCheck style window stateType shadowType area widget detail x y width height = + with area $ \ areaPtr -> [_$_] + withUTFString detail $ \ detailPtr -> [_$_] + {#call gtk_paint_check#} + (toStyle style) + window + ((fromIntegral . fromEnum) stateType) + ((fromIntegral . fromEnum) shadowType) + (castPtr areaPtr) + (toWidget widget) + detailPtr + (fromIntegral x) + (fromIntegral y) + (fromIntegral width) + (fromIntegral height) + +-- | Draws a diamond in the given rectangle on window using the given parameters. +paintDiamond :: (StyleClass style, WidgetClass widget) => [_$_] + style [_$_] + -> DrawWindow [_$_] + -> StateType [_$_] + -> ShadowType [_$_] + -> Rectangle [_$_] + -> widget [_$_] + -> String + -> Int + -> Int + -> Int + -> Int + -> IO () +paintDiamond style window stateType shadowType area widget detail x y width height = + with area $ \ areaPtr -> [_$_] + withUTFString detail $ \ detailPtr -> [_$_] + {#call gtk_paint_diamond#} + (toStyle style) + window + ((fromIntegral . fromEnum) stateType) + ((fromIntegral . fromEnum) shadowType) + (castPtr areaPtr) + (toWidget widget) + detailPtr + (fromIntegral x) + (fromIntegral y) + (fromIntegral width) + (fromIntegral height) + +-- | Draws an extension, i.e. a notebook tab. +paintExtension :: (StyleClass style, WidgetClass widget) => [_$_] + style [_$_] + -> DrawWindow [_$_] + -> StateType [_$_] + -> ShadowType [_$_] + -> Rectangle [_$_] + -> widget [_$_] + -> String + -> Int ... [truncated message content] |