From: Axel S. <si...@co...> - 2009-02-01 13:45:51
|
Sun Feb 1 08:43:39 EST 2009 Axel Simon <Axe...@en...> * Resurrect the simple text API for ComboBox and ComboBoxEntry. Adapt the demo. Include demo in 'make installcheck'. hunk ./Makefile.am 2877 - demo/graphic demo/unicode demo/soe + demo/graphic demo/unicode demo/soe demo/menu hunk ./demo/menu/ComboDemo.hs 16 - (combo, store) <- - comboBoxEntryNewText id (words "ice-cream turkey pasta sandwich steak") + combo <- comboBoxEntryNewText + mapM_ (comboBoxAppendText combo) + (words "ice-cream turkey pasta sandwich steak") + hunk ./demo/menu/ComboDemo.hs 31 + store <- comboBoxGetModelText combo hunk ./gtk/Graphics/UI/Gtk/MenuComboToolbar/ComboBox.chs.pp 77 + +-- ** Simple Text API + comboBoxSetModelText, + comboBoxGetModelText, + comboBoxAppendText, + comboBoxInsertText, + comboBoxPrependText, + comboBoxRemoveText, + +-- ** Standard API hunk ./gtk/Graphics/UI/Gtk/MenuComboToolbar/ComboBox.chs.pp 158 - mkFunPtrDestroyNotify) + mkFunPtrDestroyNotify, + Quark, objectSetAttribute, objectGetAttributeUnsafe ) hunk ./gtk/Graphics/UI/Gtk/MenuComboToolbar/ComboBox.chs.pp 163 - receiveTreeIter) + receiveTreeIter, + comboQuark) hunk ./gtk/Graphics/UI/Gtk/MenuComboToolbar/ComboBox.chs.pp 168 -import Graphics.UI.Gtk.ModelView.ListStore ( ListStore, listStoreNew ) +import Graphics.UI.Gtk.ModelView.ListStore ( ListStore, listStoreNew, + listStoreInsert, listStorePrepend, listStoreAppend, listStoreRemove ) hunk ./gtk/Graphics/UI/Gtk/MenuComboToolbar/ComboBox.chs.pp 171 - cellLayoutPackStart ) + cellLayoutPackStart, cellLayoutClear ) hunk ./gtk/Graphics/UI/Gtk/MenuComboToolbar/ComboBox.chs.pp 188 --- | Convenience function which constructs a new text combo box, which is a --- 'ComboBox' just displaying strings. If you use this function to create a --- text combo box, you can supply the @id@ function as first argument. In this --- case 'comboBoxNewText' will return a @'Graphics.UI.Gtk.ModelView.ListStore' --- String@ containing the initial list of strings. +-- | Convenience function which constructs a new text combo box that is a +-- 'ComboBox' just displaying strings. This function internally calls +-- 'comboBoxSetModelText' after creating a new combo box. hunk ./gtk/Graphics/UI/Gtk/MenuComboToolbar/ComboBox.chs.pp 192 -comboBoxNewText :: - (a -> String) -- ^ a function to extract elements from a the store - -> [a] -- ^ the initial contents of the store - -> IO (ComboBox, ListStore a) -- the resulting combo box and the store -comboBoxNewText extract initial = do - store <- listStoreNew initial - combo <- comboBoxNewWithModel store - ren <- cellRendererTextNew - cellLayoutPackStart combo ren True - cellLayoutSetAttributes combo ren store (\a -> [cellText := extract a]) - return (combo, store) +comboBoxNewText :: IO ComboBox +comboBoxNewText = do + combo <- comboBoxNew + comboBoxSetModelText combo + return combo hunk ./gtk/Graphics/UI/Gtk/MenuComboToolbar/ComboBox.chs.pp 213 +-- the text API + +-- | Create a combo box that holds strings. +-- +-- This function stores a 'Graphics.UI.Gtk.ModelView.ListStore' with the +-- widget that contains only strings. This model is also returned when calling +-- 'comboBoxGetModel'. Note that only the functions 'comboBoxAppendText', +-- 'comboBoxInsertText', 'comboBoxPrependText' and 'comboBoxRemoveText' should +-- be called on this widget once 'comboBoxSetModelText' is called. Any +-- exisiting model or renderers are removed before setting the new text model. +-- +comboBoxSetModelText :: ComboBoxClass self => self -> IO (ListStore String) +comboBoxSetModelText combo = do + cellLayoutClear (toComboBox combo) + store <- listStoreNew ([] :: [String]) + comboBoxSetModel combo (Just store) + ren <- cellRendererTextNew + cellLayoutPackStart (toComboBox combo) ren True + cellLayoutSetAttributes (toComboBox combo) ren store (\a -> [cellText := a]) + objectSetAttribute comboQuark combo (Just store) + return store + +-- | Retrieve the model that was created with 'comboBoxSetModelText'. +-- +comboBoxGetModelText :: ComboBoxClass self => self -> IO (ListStore String) +comboBoxGetModelText self = do + (Just store) <- objectGetAttributeUnsafe comboQuark (toComboBox self) + return store + +-- %hash c:7228 d:5c35 +-- | Appends @string@ to the list of strings stored in @comboBox@. Note that +-- you can only use this function with combo boxes constructed with +-- 'comboBoxNewText'. Returns the index of the appended text. +-- +comboBoxAppendText :: ComboBoxClass self => self -> String -> IO Int +comboBoxAppendText self text = do + store <- comboBoxGetModelText self + listStoreAppend store text + [_$_] +-- %hash c:41de d:8ab0 +-- | Inserts @string@ at @position@ in the list of strings stored in +-- @comboBox@. Note that you can only use this function with combo boxes +-- constructed with 'comboBoxNewText'. +-- +comboBoxInsertText :: ComboBoxClass self => self + -> Int -- ^ @position@ - An index to insert @text@. + -> String -- ^ @text@ - A string. + -> IO () +comboBoxInsertText self position text = do + store <- comboBoxGetModelText self + listStoreInsert store position text + [_$_] +-- %hash c:98ea d:9fab +-- | Prepends @string@ to the list of strings stored in @comboBox@. Note that +-- you can only use this function with combo boxes constructed with +-- 'comboBoxNewText'. +-- +comboBoxPrependText :: ComboBoxClass self => self -> String -> IO () +comboBoxPrependText self text = do + store <- comboBoxGetModelText self + listStorePrepend store text + +-- %hash c:7ff6 d:ffbf +-- | Removes the string at @position@ from @comboBox@. Note that you can only +-- use this function with combo boxes constructed with 'comboBoxNewText'. +-- +comboBoxRemoveText :: ComboBoxClass self => self + -> Int -- ^ @position@ - Index of the item to remove. + -> IO () +comboBoxRemoveText self position = do + store <- comboBoxGetModelText self + listStoreRemove store position + + + hunk ./gtk/Graphics/UI/Gtk/MenuComboToolbar/ComboBoxEntry.chs.pp 73 - comboBoxEntryNewWithModel, hunk ./gtk/Graphics/UI/Gtk/MenuComboToolbar/ComboBoxEntry.chs.pp 74 + comboBoxEntryNewWithModel, hunk ./gtk/Graphics/UI/Gtk/MenuComboToolbar/ComboBoxEntry.chs.pp 77 + comboBoxEntrySetModelText, + hunk ./gtk/Graphics/UI/Gtk/MenuComboToolbar/ComboBoxEntry.chs.pp 121 +-- | Creates a new 'ComboBoxEntry' with a store containing strings. +-- See 'comboBoxEntrySetModelText'. +-- +comboBoxEntryNewText :: IO ComboBoxEntry +comboBoxEntryNewText = do + combo <- comboBoxEntryNew + comboBoxEntrySetModelText combo + return combo + [_$_] hunk ./gtk/Graphics/UI/Gtk/MenuComboToolbar/ComboBoxEntry.chs.pp 143 --- | Convenience function which constructs a new editable text combo box, --- which is a 'ComboBoxEntry' just displaying strings. Note that this --- function does not setup any functionality to insert newly typed --- text into the model. See the module introduction for information --- about this. --- -comboBoxEntryNewText :: - (a -> String) -- ^ a function to extract elements from a the store - -> [a] -- ^ the initial entries in the 'ComboBoxEntry' - -> IO (ComboBoxEntry, ListStore a) -comboBoxEntryNewText extract initial = do - store <- listStoreNew initial - let colId = makeColumnIdString 0 - customStoreSetColumn store colId extract - combo <- makeNewObject mkComboBoxEntry $ - liftM (castPtr :: Ptr Widget -> Ptr ComboBoxEntry) $ - {# call gtk_combo_box_entry_new_with_model #} - (toTreeModel store) - (fromIntegral (columnIdToNumber colId)) - return (combo, store) - hunk ./gtk/Graphics/UI/Gtk/MenuComboToolbar/ComboBoxEntry.chs.pp 146 +-- | Set a model box that holds strings. +-- +-- This function stores a +-- 'Graphics.UI.Gtk.ModelView.ListStore' with the widget that contains only +-- strings. This model is also returned when calling 'comboBoxGetModel'. Note +-- that only the functions 'comboBoxAppendText', 'comboBoxInsertText', +-- 'comboBoxPrependText' and 'comboBoxRemoveText' should be called on this +-- widget once 'comboBoxSetModelText' is called. Any exisiting model or +-- renderers are removed before setting the new text model. In order to +-- respond to new texts that the user enters, it is necessary to connect to +-- the 'Graphics.UI.Gtk.Entry.Entry.entryActivate' signal of the contained +-- 'Graphics.UI.Gtk.Entry.Entry.Entry' an insert the text into the text model +-- which can be retrieved with +-- 'Graphics.UI.Gtk.MenuComboToolbar.ComboBox.comboBoxGetModelText'. +-- +comboBoxEntrySetModelText :: ComboBoxEntryClass self => self -> + IO (ListStore String) +comboBoxEntrySetModelText combo = do + store <- listStoreNew ([] :: [String]) + comboBoxSetModel combo (Just store) + let colId = makeColumnIdString 0 + customStoreSetColumn store colId id + comboBoxEntrySetTextColumn (toComboBoxEntry combo) colId + objectSetAttribute comboQuark (toComboBoxEntry combo) (Just store) + return store + hunk ./gtk/Graphics/UI/Gtk/ModelView/Types.chs 58 - ColumnId(..), [_$_] + ColumnId(..), + [_$_] + -- Storing the model in a ComboBox + comboQuark, [_$_] hunk ./gtk/Graphics/UI/Gtk/ModelView/Types.chs 68 +import System.Glib.GObject (Quark, quarkFromString) hunk ./gtk/Graphics/UI/Gtk/ModelView/Types.chs 251 +-- it shouldn't matter if the following function is actually inlined +{-# NOINLINE comboQuark #-} [_$_] +comboQuark :: Quark +comboQuark = + unsafePerformIO $ quarkFromString "comboBoxHaskellStringModelQuark" + [_$_] |