Fri Nov 13 18:13:19 EST 2009 Axel Simon <Axe...@en...> * Add a name field to Attributes, whenever this is possible. Add a function to set the attributes of CellRenderer using ColumnIds, thereby allowing exactly the same column-based interface as Gtk does. hunk ./glib/System/Glib/Attributes.hs 72 + newNamedAttr, + readNamedAttr, + writeNamedAttr, hunk ./glib/System/Glib/Attributes.hs 92 -data ReadWriteAttr o a b = Attr !(o -> IO a) !(o -> b -> IO ()) +data ReadWriteAttr o a b = Attr String !(o -> IO a) !(o -> b -> IO ()) hunk ./glib/System/Glib/Attributes.hs 94 +instance Show (ReadWriteAttr o a b) where + show (Attr str _ _) = str + +-- | Create a new attribute with a getter and setter function. +newNamedAttr :: String -> (o -> IO a) -> (o -> b -> IO ()) -> ReadWriteAttr o a b +newNamedAttr prop getter setter = Attr prop getter setter + +-- | Create a new read-only attribute. +readNamedAttr :: String -> (o -> IO a) -> ReadAttr o a +readNamedAttr prop getter = Attr prop getter (\_ _ -> return ()) + +-- | Create a new write-only attribute. +writeNamedAttr :: String -> (o -> b -> IO ()) -> WriteAttr o b +writeNamedAttr prop setter = Attr prop (\_ -> return ()) setter hunk ./glib/System/Glib/Attributes.hs 111 -newAttr getter setter = Attr getter setter +newAttr getter setter = Attr "unnamed attribute" getter setter hunk ./glib/System/Glib/Attributes.hs 115 -readAttr getter = Attr getter (\_ _ -> return ()) +readAttr getter = Attr "unnamed attribute" getter (\_ _ -> return ()) hunk ./glib/System/Glib/Attributes.hs 119 -writeAttr setter = Attr (\_ -> return ()) setter - +writeAttr setter = Attr "unnamed attribute" (\_ -> return ()) setter hunk ./glib/System/Glib/Attributes.hs 148 - app (Attr getter setter := x) = setter obj x - app (Attr getter setter :~ f) = getter obj >>= \v -> setter obj (f v) - app (Attr getter setter :=> x) = x >>= setter obj - app (Attr getter setter :~> f) = getter obj >>= f >>= setter obj + app (Attr _ getter setter := x) = setter obj x + app (Attr _ getter setter :~ f) = getter obj >>= \v -> setter obj (f v) + app (Attr _ getter setter :=> x) = x >>= setter obj + app (Attr _ getter setter :~> f) = getter obj >>= f >>= setter obj hunk ./glib/System/Glib/Attributes.hs 153 - app (Attr getter setter ::= f) = setter obj (f obj) - app (Attr getter setter ::~ f) = getter obj >>= \v -> setter obj (f obj v) + app (Attr _ getter setter ::= f) = setter obj (f obj) + app (Attr _ getter setter ::~ f) = getter obj >>= \v -> setter obj (f obj v) hunk ./glib/System/Glib/Attributes.hs 158 -get o (Attr getter setter) = getter o +get o (Attr _ getter setter) = getter o hunk ./glib/System/Glib/GObject.chs.pp 72 -import System.Glib.Attributes (newAttr, Attr) +import System.Glib.Attributes (newNamedAttr, Attr) hunk ./glib/System/Glib/GObject.chs.pp 205 - attr <- quarkFromString ("Gtk2HsAttr"++show cnt) - return (newAttr (objectGetAttributeUnsafe attr) - (objectSetAttribute attr)) [_$_] + let propName = "Gtk2HsAttr"++show cnt + attr <- quarkFromString propName + return (newNamedAttr propName (objectGetAttributeUnsafe attr) + (objectSetAttribute attr)) [_$_] hunk ./glib/System/Glib/Properties.chs 104 - newAttr, readAttr, writeAttr) + newNamedAttr, readNamedAttr, writeNamedAttr) hunk ./glib/System/Glib/Properties.chs 233 - newAttr (objectGetPropertyInt propName) (objectSetPropertyInt propName) + newNamedAttr propName (objectGetPropertyInt propName) (objectSetPropertyInt propName) hunk ./glib/System/Glib/Properties.chs 237 - readAttr (objectGetPropertyInt propName) + readNamedAttr propName (objectGetPropertyInt propName) hunk ./glib/System/Glib/Properties.chs 241 - newAttr (objectGetPropertyUInt propName) (objectSetPropertyUInt propName) + newNamedAttr propName (objectGetPropertyUInt propName) (objectSetPropertyUInt propName) hunk ./glib/System/Glib/Properties.chs 245 - newAttr (objectGetPropertyChar propName) (objectSetPropertyChar propName) + newNamedAttr propName (objectGetPropertyChar propName) (objectSetPropertyChar propName) hunk ./glib/System/Glib/Properties.chs 249 - writeAttr (objectSetPropertyUInt propName) + writeNamedAttr propName (objectSetPropertyUInt propName) hunk ./glib/System/Glib/Properties.chs 253 - newAttr (objectGetPropertyBool propName) (objectSetPropertyBool propName) + newNamedAttr propName (objectGetPropertyBool propName) (objectSetPropertyBool propName) hunk ./glib/System/Glib/Properties.chs 257 - readAttr (objectGetPropertyBool propName) + readNamedAttr propName (objectGetPropertyBool propName) hunk ./glib/System/Glib/Properties.chs 261 - newAttr (objectGetPropertyFloat propName) (objectSetPropertyFloat propName) + newNamedAttr propName (objectGetPropertyFloat propName) (objectSetPropertyFloat propName) hunk ./glib/System/Glib/Properties.chs 265 - newAttr (objectGetPropertyDouble propName) (objectSetPropertyDouble propName) + newNamedAttr propName (objectGetPropertyDouble propName) (objectSetPropertyDouble propName) hunk ./glib/System/Glib/Properties.chs 269 - newAttr (objectGetPropertyEnum gtype propName) (objectSetPropertyEnum gtype propName) + newNamedAttr propName (objectGetPropertyEnum gtype propName) (objectSetPropertyEnum gtype propName) hunk ./glib/System/Glib/Properties.chs 273 - readAttr (objectGetPropertyEnum gtype propName) + readNamedAttr propName (objectGetPropertyEnum gtype propName) hunk ./glib/System/Glib/Properties.chs 277 - writeAttr (objectSetPropertyEnum gtype propName) + writeNamedAttr propName (objectSetPropertyEnum gtype propName) hunk ./glib/System/Glib/Properties.chs 281 - newAttr (objectGetPropertyFlags gtype propName) (objectSetPropertyFlags gtype propName) + newNamedAttr propName (objectGetPropertyFlags gtype propName) (objectSetPropertyFlags gtype propName) hunk ./glib/System/Glib/Properties.chs 285 - newAttr (objectGetPropertyString propName) (objectSetPropertyString propName) + newNamedAttr propName (objectGetPropertyString propName) (objectSetPropertyString propName) hunk ./glib/System/Glib/Properties.chs 289 - readAttr (objectGetPropertyString propName) + readNamedAttr propName (objectGetPropertyString propName) hunk ./glib/System/Glib/Properties.chs 293 - writeAttr (objectSetPropertyString propName) + writeNamedAttr propName (objectSetPropertyString propName) hunk ./glib/System/Glib/Properties.chs 297 - newAttr (objectGetPropertyMaybeString propName) (objectSetPropertyMaybeString propName) + newNamedAttr propName (objectGetPropertyMaybeString propName) (objectSetPropertyMaybeString propName) hunk ./glib/System/Glib/Properties.chs 301 - readAttr (objectGetPropertyMaybeString propName) + readNamedAttr propName (objectGetPropertyMaybeString propName) hunk ./glib/System/Glib/Properties.chs 305 - writeAttr (objectSetPropertyMaybeString propName) + writeNamedAttr propName (objectSetPropertyMaybeString propName) hunk ./glib/System/Glib/Properties.chs 309 - newAttr (objectGetPropertyBoxedOpaque peek gtype propName) (objectSetPropertyBoxedOpaque with gtype propName) + newNamedAttr propName (objectGetPropertyBoxedOpaque peek gtype propName) (objectSetPropertyBoxedOpaque with gtype propName) hunk ./glib/System/Glib/Properties.chs 313 - readAttr (objectGetPropertyBoxedOpaque peek gtype propName) + readNamedAttr propName (objectGetPropertyBoxedOpaque peek gtype propName) hunk ./glib/System/Glib/Properties.chs 317 - writeAttr (objectSetPropertyBoxedOpaque with gtype propName) + writeNamedAttr propName (objectSetPropertyBoxedOpaque with gtype propName) hunk ./glib/System/Glib/Properties.chs 321 - newAttr (objectGetPropertyBoxedStorable gtype propName) (objectSetPropertyBoxedStorable gtype propName) + newNamedAttr propName (objectGetPropertyBoxedStorable gtype propName) (objectSetPropertyBoxedStorable gtype propName) hunk ./glib/System/Glib/Properties.chs 325 - newAttr (objectGetPropertyGObject gtype propName) (objectSetPropertyGObject gtype propName) + newNamedAttr propName (objectGetPropertyGObject gtype propName) (objectSetPropertyGObject gtype propName) hunk ./glib/System/Glib/Properties.chs 329 - newAttr (objectGetPropertyMaybeGObject gtype propName) (objectSetPropertyMaybeGObject gtype propName) + newNamedAttr propName (objectGetPropertyMaybeGObject gtype propName) (objectSetPropertyMaybeGObject gtype propName) hunk ./glib/System/Glib/Properties.chs 333 - writeAttr (objectSetPropertyGObject gtype propName) + writeNamedAttr propName (objectSetPropertyGObject gtype propName) hunk ./glib/System/Glib/Properties.chs 337 - readAttr (objectGetPropertyGObject gtype propName) + readNamedAttr propName (objectGetPropertyGObject gtype propName) hunk ./gtk/Graphics/UI/Gtk/ModelView/CellLayout.chs.pp 60 + cellLayoutClearAttributes, +#if GTK_CHECK_VERSION(2,12,0) + cellLayoutGetCells, +#endif + cellLayoutAddColumnAttribute, hunk ./gtk/Graphics/UI/Gtk/ModelView/CellLayout.chs.pp 67 - cellLayoutClearAttributes hunk ./gtk/Graphics/UI/Gtk/ModelView/CellLayout.chs.pp 150 +#if GTK_CHECK_VERSION(2,12,0) +-- | Returns the cell renderers which have been added to @cellLayout@. +-- +-- * Available since Gtk+ version 2.12 +-- +cellLayoutGetCells :: CellLayoutClass self => self + -> IO [CellRenderer] -- ^ returns a list of cell renderers +cellLayoutGetCells self = + {# call gtk_cell_layout_get_cells #} + (toCellLayout self) + >>= fromGList + >>= mapM (makeNewGObject mkCellRenderer . return) +#endif + +-- | Adds an attribute mapping to the renderer @cell@. The @column@ is +-- the 'ColumnId' of the model to get a value from, and the @attribute@ is the +-- parameter on @cell@ to be set from the value. So for example if column 2 of +-- the model contains strings, you could have the \"text\" attribute of a +-- 'CellRendererText' get its values from column 2. +-- +cellLayoutAddColumnAttribute :: (CellLayoutClass self, CellRendererClass cell) => self + -> cell -- ^ @cell@ - A 'CellRenderer'. + -> ReadWriteAttr cell a v -- ^ @attribute@ - An attribute of a renderer. + -> ColumnId row v -- ^ @column@ - The virtual column of the model from which to [_$_] + -- retrieve the attribute. + -> IO () +cellLayoutAddColumnAttribute self cell attr column = + withCString (show attr) $ \attributePtr -> + {# call gtk_cell_layout_add_attribute #} + (toCellLayout self) + (toCellRenderer cell) + attributePtr + (fromIntegral (columnIdToNumber column)) + + |