1{-# LANGUAGE CPP #-}
2-- -*-haskell-*-
3--  GIMP Toolkit (GTK) Widget IconView
4--
5--  Author : Duncan Coutts
6--
7--  Created: 25 March 2005
8--
9--  Copyright (C) 2005-2007 Duncan Coutts, Axel Simon
10--
11--  This library is free software; you can redistribute it and/or
12--  modify it under the terms of the GNU Lesser General Public
13--  License as published by the Free Software Foundation; either
14--  version 2.1 of the License, or (at your option) any later version.
15--
16--  This library is distributed in the hope that it will be useful,
17--  but WITHOUT ANY WARRANTY; without even the implied warranty of
18--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19--  Lesser General Public License for more details.
20--
21-- |
22-- Maintainer  : gtk2hs-users@lists.sourceforge.net
23-- Stability   : provisional
24-- Portability : portable (depends on GHC)
25--
26-- A widget which displays a list of icons in a grid
27--
28-- * Module available since Gtk+ version 2.6
29--
30module Graphics.UI.Gtk.ModelView.IconView (
31-- * Detail
32--
33-- | 'IconView' provides an alternative view on a list model. It displays the
34-- model as a grid of icons with labels. Like 'TreeView', it allows to select
35-- one or multiple items (depending on the selection mode, see
36-- 'iconViewSetSelectionMode'). In addition to selection with the arrow keys,
37-- 'IconView' supports rubberband selection, which is controlled by dragging
38-- the pointer.
39
40-- * Class Hierarchy
41--
42-- |
43-- @
44-- |  'GObject'
45-- |   +----'Object'
46-- |         +----'Widget'
47-- |               +----'Container'
48-- |                     +----IconView
49-- @
50
51#if GTK_CHECK_VERSION(2,6,0)
52-- * Types
53  IconView,
54  IconViewClass,
55  castToIconView, gTypeIconView,
56  toIconView,
57
58-- * Constructors
59  iconViewNew,
60  iconViewNewWithModel,
61
62-- * Methods
63  iconViewSetModel,
64  iconViewGetModel,
65  iconViewSetTextColumn,
66  iconViewGetTextColumn,
67  iconViewSetMarkupColumn,
68  iconViewGetMarkupColumn,
69  iconViewSetPixbufColumn,
70  iconViewGetPixbufColumn,
71  iconViewGetPathAtPos,
72  iconViewSelectedForeach,
73  iconViewSetSelectionMode,
74  iconViewGetSelectionMode,
75#if GTK_MAJOR_VERSION < 3
76  iconViewSetOrientation,
77  iconViewGetOrientation,
78#endif
79  iconViewSetColumns,
80  iconViewGetColumns,
81  iconViewSetItemWidth,
82  iconViewGetItemWidth,
83  iconViewSetSpacing,
84  iconViewGetSpacing,
85  iconViewSetRowSpacing,
86  iconViewGetRowSpacing,
87  iconViewSetColumnSpacing,
88  iconViewGetColumnSpacing,
89  iconViewSetMargin,
90  iconViewGetMargin,
91  iconViewSelectPath,
92  iconViewUnselectPath,
93  iconViewPathIsSelected,
94  iconViewGetSelectedItems,
95  iconViewSelectAll,
96  iconViewUnselectAll,
97  iconViewItemActivated,
98#if GTK_CHECK_VERSION(2,8,0)
99  iconViewGetItemAtPos,
100  iconViewSetCursor,
101  iconViewGetCursor,
102  iconViewScrollToPath,
103  iconViewGetVisibleRange,
104#if GTK_CHECK_VERSION(2,10,0)
105  iconViewEnableModelDragSource,
106  iconViewEnableModelDragDest,
107  iconViewUnsetModelDragSource,
108  iconViewUnsetModelDragDest,
109#endif
110  iconViewSetReorderable,
111  iconViewGetReorderable,
112#endif
113#if GTK_CHECK_VERSION(2,22,0)
114  iconViewGetItemRow,
115  iconViewGetItemColumn,
116#endif
117
118-- * Attributes
119  iconViewSelectionMode,
120  iconViewTextColumn,
121  iconViewMarkupColumn,
122  iconViewPixbufColumn,
123  iconViewModel,
124  iconViewColumns,
125  iconViewItemWidth,
126  iconViewSpacing,
127  iconViewRowSpacing,
128  iconViewColumnSpacing,
129  iconViewMargin,
130  iconViewOrientation,
131#if GTK_CHECK_VERSION(2,8,0)
132  iconViewReorderable,
133#endif
134#if GTK_CHECK_VERSION(2,22,0)
135  iconViewItemOrientation,
136#endif
137
138-- * Signals
139  setIconViewScrollAdjustments,
140  itemActivated,
141  selectionChanged
142#endif
143  ) where
144
145import Control.Monad    (liftM)
146
147import System.Glib.FFI
148import System.Glib.UTFString
149import System.Glib.Attributes
150import System.Glib.Properties
151import System.Glib.GList                        (fromGList)
152import System.Glib.Flags
153import Graphics.UI.Gtk.Abstract.Object          (makeNewObject)
154import Graphics.UI.Gtk.Gdk.Enums                (DragAction(..))
155import Graphics.UI.Gtk.Gdk.Events               (Modifier(..))
156{#import Graphics.UI.Gtk.Types#}
157{#import Graphics.UI.Gtk.Signals#}
158{#import Graphics.UI.Gtk.General.Enums#}        (Orientation, SelectionMode)
159{#import Graphics.UI.Gtk.ModelView.TreeModel#}
160{#import Graphics.UI.Gtk.ModelView.Types#}
161{#import Graphics.UI.Gtk.General.DNDTypes#}     (TargetList(..))
162
163{# context lib="gtk" prefix="gtk" #}
164
165#if GTK_CHECK_VERSION(2,6,0)
166--------------------
167-- Constructors
168
169-- | Creates a new 'IconView' widget
170--
171iconViewNew :: IO IconView
172iconViewNew =
173  makeNewObject mkIconView $
174  liftM (castPtr :: Ptr Widget -> Ptr IconView) $
175  {# call gtk_icon_view_new #}
176
177-- %hash c:dbf4
178-- | Creates a new 'IconView' widget with the model @model@ and defines
179--   how to extract a string and a pixbuf from the model.
180--
181iconViewNewWithModel :: TreeModelClass model =>
182    model -- ^ @model@ - The model.
183 -> IO IconView
184iconViewNewWithModel model =
185  makeNewObject mkIconView $
186    liftM (castPtr :: Ptr Widget -> Ptr IconView) $
187    {# call gtk_icon_view_new_with_model #}
188    (toTreeModel model)
189
190--------------------
191-- Methods
192
193-- %hash c:5ba8 d:c5c8
194-- | Sets the model for a 'IconView'. If the @iconView@ already has a model
195-- set, it will remove it before setting the new model. If @model@ is
196-- @Nothing@, then it will unset the old model.
197--
198iconViewSetModel :: (IconViewClass self, TreeModelClass model) => self
199 -> Maybe model -- ^ @model@ - The model.
200 -> IO ()
201iconViewSetModel self model =
202  {# call gtk_icon_view_set_model #}
203    (toIconView self)
204    (maybe (TreeModel nullForeignPtr) toTreeModel model)
205
206-- %hash c:6709 d:c0c5
207-- | Returns the model the 'IconView' is based on. Returns @Nothing@ if the
208-- model is unset.
209--
210iconViewGetModel :: IconViewClass self => self
211 -> IO (Maybe TreeModel) -- ^ returns a 'TreeModel', or @Nothing@ if none is
212                         -- currently being used.
213iconViewGetModel self =
214  maybeNull (makeNewGObject mkTreeModel) $
215  {# call unsafe gtk_icon_view_get_model #}
216    (toIconView self)
217
218-- %hash c:c3fe d:fb7b
219-- | Sets the column of the text for entries in the 'IconView'. If a markup
220-- source is set using 'iconViewSetMarkupSource', then the text source is
221-- ignored.
222--
223iconViewSetTextColumn :: (IconViewClass self, GlibString string) => self
224 -> ColumnId row string -- ^ @column@ - A column in the currently used model.
225 -> IO ()
226iconViewSetTextColumn self column =
227  {# call gtk_icon_view_set_text_column #}
228    (toIconView self)
229    ((fromIntegral . columnIdToNumber) column)
230
231-- | Returns the column with text for @iconView@.
232--
233iconViewGetTextColumn :: (IconViewClass self, GlibString string) => self
234 -> IO (ColumnId row string) -- ^ returns the text column, or 'invalidColumnId' if it's unset.
235iconViewGetTextColumn self =
236  liftM (makeColumnIdString . fromIntegral) $
237  {# call gtk_icon_view_get_text_column #}
238    (toIconView self)
239
240
241-- %hash c:995f d:801c
242-- | Sets the column of the text for entries in the 'IconView' as a markup
243-- string (see 'Graphics.Rendering.Pango.Markup'). A text source that is set
244-- using 'iconViewSetTextSource' is ignored once a markup source is set.
245--
246iconViewSetMarkupColumn :: (IconViewClass self, GlibString markup) => self
247 -> ColumnId row markup -- ^ @column@ - A column in the currently used model.
248 -> IO ()
249iconViewSetMarkupColumn self column =
250  {# call gtk_icon_view_set_markup_column #}
251    (toIconView self)
252    ((fromIntegral . columnIdToNumber) column)
253
254-- | Returns the column with markup text for @iconView@.
255--
256iconViewGetMarkupColumn :: (IconViewClass self, GlibString markup) => self
257 -> IO (ColumnId row markup) -- ^ returns the markup column, or 'invalidColumnId' if it's unset.
258iconViewGetMarkupColumn self =
259  liftM (makeColumnIdString . fromIntegral) $
260  {# call gtk_icon_view_get_markup_column #}
261    (toIconView self)
262
263
264-- %hash c:4079 d:bf8
265-- | Sets the column of the 'Graphics.UI.Gtk.Gdk.Pixbuf' for entries in the
266-- 'IconView'.
267--
268iconViewSetPixbufColumn :: IconViewClass self => self
269 -> ColumnId row Pixbuf -- ^ @column@ - A column in the currently used model.
270 -> IO ()
271iconViewSetPixbufColumn self column =
272  {# call gtk_icon_view_set_pixbuf_column #}
273    (toIconView self)
274    ((fromIntegral . columnIdToNumber) column)
275
276-- | Returns the column with pixbufs for @iconView@.
277--
278iconViewGetPixbufColumn :: IconViewClass self => self
279 -> IO (ColumnId row Pixbuf) -- ^ returns the pixbuf column, or 'invalidColumnId' if it's unset.
280iconViewGetPixbufColumn self =
281  liftM (makeColumnIdPixbuf . fromIntegral) $
282  {# call gtk_icon_view_get_pixbuf_column #}
283    (toIconView self)
284
285-- %hash c:2486 d:5e7
286-- | Finds the path at the point (@x@, @y@), relative to widget coordinates.
287-- See 'iconViewGetItemAtPos', if you are also interested in the cell at the
288-- specified position.
289--
290iconViewGetPathAtPos :: IconViewClass self => self
291 -> Int         -- ^ @x@ - The x position to be identified
292 -> Int         -- ^ @y@ - The y position to be identified
293 -> IO TreePath -- ^ returns The 'TreePath' corresponding to the icon or @[]@
294                -- if no icon exists at that position.
295iconViewGetPathAtPos self x y =
296  {# call gtk_icon_view_get_path_at_pos #}
297    (toIconView self)
298    (fromIntegral x)
299    (fromIntegral y)
300  >>= fromTreePath
301
302-- %hash c:dfc5
303-- | Calls a function for each selected icon. Note that the model or selection
304-- cannot be modified from within this function.
305--
306iconViewSelectedForeach :: IconViewClass self => self
307 -> (TreePath -> IO ()) -- ^ @(\path -> ...)@ - The funcion to call for each
308                        -- selected icon.
309 -> IO ()
310iconViewSelectedForeach self func = do
311  funcPtr <- mkIconViewForeachFunc (\_ tpPtr _ -> do
312    path <- peekTreePath tpPtr
313    func path
314    )
315  {# call gtk_icon_view_selected_foreach #}
316    (toIconView self)
317    funcPtr
318    nullPtr
319  freeHaskellFunPtr funcPtr
320
321{# pointer IconViewForeachFunc #}
322
323foreign import ccall "wrapper" mkIconViewForeachFunc ::
324  (Ptr IconView -> Ptr NativeTreePath -> Ptr () -> IO ()) -> IO IconViewForeachFunc
325
326-- | Sets the selection mode of the @iconView@.
327--
328iconViewSetSelectionMode :: IconViewClass self => self
329 -> SelectionMode -- ^ @mode@ - The selection mode
330 -> IO ()
331iconViewSetSelectionMode self mode =
332  {# call gtk_icon_view_set_selection_mode #}
333    (toIconView self)
334    ((fromIntegral . fromEnum) mode)
335
336-- | Gets the selection mode of the @iconView@.
337--
338iconViewGetSelectionMode :: IconViewClass self => self
339 -> IO SelectionMode -- ^ returns the current selection mode
340iconViewGetSelectionMode self =
341  liftM (toEnum . fromIntegral) $
342  {# call gtk_icon_view_get_selection_mode #}
343    (toIconView self)
344
345#if GTK_MAJOR_VERSION < 3
346-- | Sets the ::orientation property which determines whether the labels are
347-- drawn beside the icons instead of below.
348--
349iconViewSetOrientation :: IconViewClass self => self
350 -> Orientation -- ^ @orientation@ - the relative position of texts and icons
351 -> IO ()
352iconViewSetOrientation self orientation =
353  {# call gtk_icon_view_set_orientation #}
354    (toIconView self)
355    ((fromIntegral . fromEnum) orientation)
356
357-- | Returns the value of the ::orientation property which determines whether
358-- the labels are drawn beside the icons instead of below.
359--
360iconViewGetOrientation :: IconViewClass self => self
361 -> IO Orientation -- ^ returns the relative position of texts and icons
362iconViewGetOrientation self =
363  liftM (toEnum . fromIntegral) $
364  {# call gtk_icon_view_get_orientation #}
365    (toIconView self)
366#endif
367
368-- %hash c:7d23 d:d4e7
369-- | Sets the ::columns property which determines in how many columns the
370-- icons are arranged. If @columns@ is -1, the number of columns will be chosen
371-- automatically to fill the available area.
372--
373iconViewSetColumns :: IconViewClass self => self
374 -> Int -- ^ @columns@ - the number of columns
375 -> IO ()
376iconViewSetColumns self columns =
377  {# call gtk_icon_view_set_columns #}
378    (toIconView self)
379    (fromIntegral columns)
380
381-- %hash c:f0f6 d:fc0e
382-- | Returns the value of the ::columns property.
383--
384iconViewGetColumns :: IconViewClass self => self
385 -> IO Int -- ^ returns the number of columns, or -1
386iconViewGetColumns self =
387  liftM fromIntegral $
388  {# call gtk_icon_view_get_columns #}
389    (toIconView self)
390
391-- %hash c:643e d:b756
392-- | Sets the ::item-width property which specifies the width to use for each
393-- item. If it is set to -1, the icon view will automatically determine a
394-- suitable item size.
395--
396iconViewSetItemWidth :: IconViewClass self => self
397 -> Int -- ^ @itemWidth@ - the width for each item
398 -> IO ()
399iconViewSetItemWidth self itemWidth =
400  {# call gtk_icon_view_set_item_width #}
401    (toIconView self)
402    (fromIntegral itemWidth)
403
404-- %hash c:9f27 d:8569
405-- | Returns the value of the ::item-width property.
406--
407iconViewGetItemWidth :: IconViewClass self => self
408 -> IO Int -- ^ returns the width of a single item, or -1
409iconViewGetItemWidth self =
410  liftM fromIntegral $
411  {# call gtk_icon_view_get_item_width #}
412    (toIconView self)
413
414-- %hash c:7e61 d:3186
415-- | Sets the ::spacing property which specifies the space which is inserted
416-- between the cells (i.e. the icon and the text) of an item.
417--
418iconViewSetSpacing :: IconViewClass self => self
419 -> Int -- ^ @spacing@ - the spacing
420 -> IO ()
421iconViewSetSpacing self spacing =
422  {# call gtk_icon_view_set_spacing #}
423    (toIconView self)
424    (fromIntegral spacing)
425
426-- %hash c:5bc1 d:a1d2
427-- | Returns the value of the ::spacing property.
428--
429iconViewGetSpacing :: IconViewClass self => self
430 -> IO Int -- ^ returns the space between cells
431iconViewGetSpacing self =
432  liftM fromIntegral $
433  {# call gtk_icon_view_get_spacing #}
434    (toIconView self)
435
436-- %hash c:dd08 d:730c
437-- | Sets the ::row-spacing property which specifies the space which is
438-- inserted between the rows of the icon view.
439--
440iconViewSetRowSpacing :: IconViewClass self => self
441 -> Int -- ^ @rowSpacing@ - the row spacing
442 -> IO ()
443iconViewSetRowSpacing self rowSpacing =
444  {# call gtk_icon_view_set_row_spacing #}
445    (toIconView self)
446    (fromIntegral rowSpacing)
447
448-- %hash c:a040 d:bc37
449-- | Returns the value of the ::row-spacing property.
450--
451iconViewGetRowSpacing :: IconViewClass self => self
452 -> IO Int -- ^ returns the space between rows
453iconViewGetRowSpacing self =
454  liftM fromIntegral $
455  {# call gtk_icon_view_get_row_spacing #}
456    (toIconView self)
457
458-- %hash c:3042 d:b4f8
459-- | Sets the ::column-spacing property which specifies the space which is
460-- inserted between the columns of the icon view.
461--
462iconViewSetColumnSpacing :: IconViewClass self => self
463 -> Int -- ^ @columnSpacing@ - the column spacing
464 -> IO ()
465iconViewSetColumnSpacing self columnSpacing =
466  {# call gtk_icon_view_set_column_spacing #}
467    (toIconView self)
468    (fromIntegral columnSpacing)
469
470-- %hash c:3818 d:c1cd
471-- | Returns the value of the ::column-spacing property.
472--
473iconViewGetColumnSpacing :: IconViewClass self => self
474 -> IO Int -- ^ returns the space between columns
475iconViewGetColumnSpacing self =
476  liftM fromIntegral $
477  {# call gtk_icon_view_get_column_spacing #}
478    (toIconView self)
479
480-- %hash c:990 d:d43c
481-- | Sets the ::margin property which specifies the space which is inserted at
482-- the top, bottom, left and right of the icon view.
483--
484iconViewSetMargin :: IconViewClass self => self
485 -> Int -- ^ @margin@ - the margin
486 -> IO ()
487iconViewSetMargin self margin =
488  {# call gtk_icon_view_set_margin #}
489    (toIconView self)
490    (fromIntegral margin)
491
492-- %hash c:a116 d:6fab
493-- | Returns the value of the ::margin property.
494--
495iconViewGetMargin :: IconViewClass self => self
496 -> IO Int -- ^ returns the space at the borders
497iconViewGetMargin self =
498  liftM fromIntegral $
499  {# call gtk_icon_view_get_margin #}
500    (toIconView self)
501
502-- %hash c:77b3
503-- | Selects the row at @path@.
504--
505iconViewSelectPath :: IconViewClass self => self
506 -> TreePath -- ^ @path@ - The 'TreePath' to be selected.
507 -> IO ()
508iconViewSelectPath self path =
509  withTreePath path $ \path ->
510  {# call gtk_icon_view_select_path #}
511    (toIconView self)
512    path
513
514-- %hash c:7e5f
515-- | Unselects the row at @path@.
516--
517iconViewUnselectPath :: IconViewClass self => self
518 -> TreePath -- ^ @path@ - The 'TreePath' to be unselected.
519 -> IO ()
520iconViewUnselectPath self path =
521  withTreePath path $ \path ->
522  {# call gtk_icon_view_unselect_path #}
523    (toIconView self)
524    path
525
526-- %hash c:8ea0
527-- | Returns @True@ if the icon pointed to by @path@ is currently selected. If
528-- @icon@ does not point to a valid location, @False@ is returned.
529--
530iconViewPathIsSelected :: IconViewClass self => self
531 -> TreePath -- ^ @path@ - A 'TreePath' to check selection on.
532 -> IO Bool  -- ^ returns @True@ if @path@ is selected.
533iconViewPathIsSelected self path =
534  liftM toBool $
535  withTreePath path $ \path ->
536  {# call gtk_icon_view_path_is_selected #}
537    (toIconView self)
538    path
539
540-- %hash c:90f8 d:9c43
541-- | Creates a list of paths of all selected items. Additionally, if you are
542-- planning on modifying the model after calling this function, you may want
543-- to convert the returned list into a list of 'TreeRowReference's. To do
544-- this, you can use 'treeRowReferenceNew'.
545--
546iconViewGetSelectedItems :: IconViewClass self => self
547 -> IO [TreePath] -- ^ returns a list of 'TreePath's, one for each selected row.
548iconViewGetSelectedItems self =
549  {# call gtk_icon_view_get_selected_items #}
550    (toIconView self)
551  >>= fromGList
552  >>= mapM fromTreePath
553
554-- | Selects all the icons. @iconView@ must has its selection mode set to
555-- 'SelectionMultiple'.
556--
557iconViewSelectAll :: IconViewClass self => self -> IO ()
558iconViewSelectAll self =
559  {# call gtk_icon_view_select_all #}
560    (toIconView self)
561
562-- | Unselects all the icons.
563--
564iconViewUnselectAll :: IconViewClass self => self -> IO ()
565iconViewUnselectAll self =
566  {# call gtk_icon_view_unselect_all #}
567    (toIconView self)
568
569-- %hash c:6916
570-- | Activates the item determined by @path@.
571--
572iconViewItemActivated :: IconViewClass self => self
573 -> TreePath -- ^ @path@ - The 'TreePath' to be activated
574 -> IO ()
575iconViewItemActivated self path =
576  withTreePath path $ \path ->
577  {# call gtk_icon_view_item_activated #}
578    (toIconView self)
579    path
580
581
582#if GTK_CHECK_VERSION(2,8,0)
583-- %hash c:3122 d:346e
584-- | Finds the path at the point (@x@, @y@), relative to widget coordinates.
585-- In contrast to 'iconViewGetPathAtPos', this function also obtains the cell
586-- at the specified position.
587--
588-- * Available since Gtk+ version 2.8
589--
590iconViewGetItemAtPos :: IconViewClass self => self
591 -> Int                   -- ^ @x@ - The x position to be identified
592 -> Int                   -- ^ @y@ - The y position to be identified
593 -> IO (Maybe (TreePath, CellRenderer))
594                          -- specified position
595iconViewGetItemAtPos self x y =
596  alloca $ \pathPtrPtr -> alloca $ \crPtrPtr -> do
597  success <- liftM toBool $ {# call gtk_icon_view_get_item_at_pos #}
598    (toIconView self)
599    (fromIntegral x)
600    (fromIntegral y)
601    (castPtr pathPtrPtr)
602    (castPtr crPtrPtr)
603  if not success then return Nothing else do
604  pathPtr <- peek pathPtrPtr
605  crPtr <- peek crPtrPtr
606  path <- fromTreePath pathPtr
607  cr <- makeNewGObject mkCellRenderer (return crPtr)
608  return (Just (path, cr))
609
610-- %hash c:357b d:32d6
611-- | Given @Left path@ as argument , sets the current keyboard focus to be at
612-- @path@, and selects it. This is useful when you want to focus the user's
613-- attention on a particular item. If @Right cell@ is given, then focus is
614-- given to the cell specified by it. Additionally, if @startEditing@ is
615-- @True@, then editing should be started in the specified cell.
616--
617-- This function is often followed by
618-- 'Graphics.UI.Gtk.Abstract.Widget.widgetGrabFocus' in order to give keyboard
619-- focus to the widget. Please note that editing can only happen when the
620-- widget is realized.
621--
622-- * Available since Gtk+ version 2.8
623--
624iconViewSetCursor :: (IconViewClass self, CellRendererClass cell) => self
625 -> (Either TreePath cell) -- ^ the path or the cell
626 -> Bool     -- ^ @startEditing@ - @True@ if the specified cell should start
627             -- being edited.
628 -> IO ()
629iconViewSetCursor self (Left path) startEditing =
630  withTreePath path $ \path ->
631  {# call gtk_icon_view_set_cursor #}
632    (toIconView self)
633    path
634    (CellRenderer nullForeignPtr)
635    (fromBool startEditing)
636iconViewSetCursor self (Right cell) startEditing =
637  {# call gtk_icon_view_set_cursor #}
638    (toIconView self)
639    (NativeTreePath nullPtr)
640    (toCellRenderer cell)
641    (fromBool startEditing)
642
643-- %hash c:3307 d:9cf8
644-- | Return a @path@ and a @cell@ with the current cursor path and cell. If the
645-- cursor isn't currently set, then @[]@ will be returned for the @path@. If no cell currently has focus,
646-- then @cell@ will be @Nothing@.
647--
648-- * Available since Gtk+ version 2.8
649--
650iconViewGetCursor :: IconViewClass self => self
651 -> IO (TreePath, Maybe CellRenderer)               -- ^ returns a @path@ to the cursor and a @cell@ if the widget has the input focus
652iconViewGetCursor self =
653  alloca $ \pathPtrPtr -> alloca $ \crPtrPtr -> do
654  {# call gtk_icon_view_get_cursor #}
655    (toIconView self)
656    (castPtr pathPtrPtr)
657    (castPtr crPtrPtr)
658  pathPtr <- peek pathPtrPtr
659  crPtr <- peek crPtrPtr
660  path <- fromTreePath pathPtr
661  cr <- if crPtr==nullPtr then return Nothing else
662        liftM Just $ makeNewGObject mkCellRenderer (return crPtr)
663  return (path, cr)
664
665-- %hash c:1c9e d:20c5
666-- | Moves the alignments of @iconView@ to the position specified by @path@.
667-- @rowAlign@ determines where the row is placed, and @colAlign@ determines
668-- where @column@ is placed. Both are expected to be between 0.0 and 1.0. 0.0
669-- means left\/top alignment, 1.0 means right\/bottom alignment, 0.5 means
670-- center.
671--
672-- If @useAlign@ is @False@, then the alignment arguments are ignored, and the
673-- tree does the minimum amount of work to scroll the item onto the screen.
674-- This means that the item will be scrolled to the edge closest to its
675-- current position. If the item is currently visible on the screen, nothing
676-- is done.
677--
678-- This function only works if the model is set, and @path@ is a valid row on
679-- the model. If the model changes before the @iconView@ is realized, the
680-- centered path will be modified to reflect this change.
681--
682-- * Available since Gtk+ version 2.8
683--
684iconViewScrollToPath :: IconViewClass self => self
685 -> TreePath -- ^ @path@ - The path of the item to move to.
686 -> Bool     -- ^ @useAlign@ - whether to use alignment arguments, or @False@.
687 -> Float    -- ^ @rowAlign@ - The vertical alignment of the item specified by
688             -- @path@.
689 -> Float    -- ^ @colAlign@ - The horizontal alignment of the item specified
690             -- by @path@.
691 -> IO ()
692iconViewScrollToPath self path useAlign rowAlign colAlign =
693  withTreePath path $ \path ->
694  {# call gtk_icon_view_scroll_to_path #}
695    (toIconView self)
696    path
697    (fromBool useAlign)
698    (realToFrac rowAlign)
699    (realToFrac colAlign)
700
701-- %hash c:8354 d:f7f3
702-- | Retrieve the first and last visible path.
703-- Note that there may be invisible paths inbetween.
704--
705-- * Available since Gtk+ version 2.8
706--
707iconViewGetVisibleRange :: IconViewClass self => self
708 -> IO (Maybe (TreePath, TreePath))
709                -- ^ returns the first and last visible path, the return value
710                -- @Nothing@ if every element is visible
711iconViewGetVisibleRange self = alloca $ \fPtrPtr -> alloca $ \lPtrPtr -> do
712  success <- liftM toBool $ {# call gtk_icon_view_get_visible_range #}
713    (toIconView self)
714    (castPtr fPtrPtr)
715    (castPtr lPtrPtr)
716  if not success then return Nothing else do
717  fPtr <- peek fPtrPtr
718  lPtr <- peek lPtrPtr
719  f <- fromTreePath fPtr
720  l <- fromTreePath lPtr
721  return (Just (f,l))
722
723#if GTK_CHECK_VERSION(2,10,0)
724-- %hash c:bd16 d:3f4f
725-- | Turns @iconView@ into a drag source for automatic DND.
726--
727-- * Available since Gtk+ version 2.10
728--
729iconViewEnableModelDragSource :: IconViewClass self => self
730  -> [Modifier]         -- ^ @startButtonMask@ - Mask of allowed buttons
731                        -- to start drag
732  -> TargetList         -- ^ @targets@ - the list of targets that the
733                        -- the view will support
734  -> [DragAction]       -- ^ @actions@ - flags denoting the possible actions
735                        -- for a drag from this widget
736  -> IO ()
737iconViewEnableModelDragSource self startButtonMask targets actions =
738  alloca $ \nTargetsPtr -> do
739  tlPtr <- {#call unsafe gtk_target_table_new_from_list#} targets nTargetsPtr
740  nTargets <- peek nTargetsPtr
741  {# call gtk_icon_view_enable_model_drag_source #}
742    (toIconView self)
743    ((fromIntegral . fromFlags) startButtonMask)
744    tlPtr
745    nTargets
746    ((fromIntegral . fromFlags) actions)
747  {#call unsafe gtk_target_table_free#} tlPtr nTargets
748
749-- %hash c:b14d d:23d7
750-- | Turns @iconView@ into a drop destination for automatic DND.
751--
752-- * Available since Gtk+ version 2.10
753--
754iconViewEnableModelDragDest :: IconViewClass self => self
755  -> TargetList                -- ^ @targets@ - the list of targets that the
756                               -- the view will support
757  -> [DragAction]              -- ^ @actions@ - flags denoting the possible actions
758                               -- for a drop into this widget
759  -> IO ()
760iconViewEnableModelDragDest self targets actions =
761  alloca $ \nTargetsPtr -> do
762  tlPtr <- {#call unsafe gtk_target_table_new_from_list#} targets nTargetsPtr
763  nTargets <- peek nTargetsPtr
764  {# call gtk_icon_view_enable_model_drag_dest #}
765    (toIconView self)
766    tlPtr
767    nTargets
768    ((fromIntegral . fromFlags) actions)
769
770-- %hash c:25b0 d:5a6b
771-- | Undoes the effect of 'iconViewEnableModelDragSource'.
772--
773-- * Available since Gtk+ version 2.10
774--
775iconViewUnsetModelDragSource :: IconViewClass self => self -> IO ()
776iconViewUnsetModelDragSource self =
777  {# call gtk_icon_view_unset_model_drag_source #}
778    (toIconView self)
779
780-- %hash c:d76d d:f18a
781-- | Undoes the effect of 'iconViewEnableModelDragDest'.
782--
783-- * Available since Gtk+ version 2.10
784--
785iconViewUnsetModelDragDest :: IconViewClass self => self -> IO ()
786iconViewUnsetModelDragDest self =
787  {# call gtk_icon_view_unset_model_drag_dest #}
788    (toIconView self)
789#endif
790
791-- %hash c:c270 d:b94d
792-- | Check if icons can be moved around.
793--
794-- * Set whether the user can use drag and drop (DND) to reorder the rows in
795--   the store. This works on both 'TreeStore' and 'ListStore' models. If @ro@
796--   is @True@, then the user can reorder the model by dragging and dropping
797--   rows.  The developer can listen to these changes by connecting to the
798--   model's signals. If you need to control which rows may be dragged or
799--   where rows may be dropped, you can override the
800--   'Graphics.UI.Gtk.ModelView.CustomStore.treeDragSourceRowDraggable'
801--   function in the default DND implementation of the model.
802--
803-- * Available since Gtk+ version 2.8
804--
805iconViewSetReorderable :: IconViewClass self => self
806 -> Bool -- ^ @reorderable@ - @True@, if the list of items can be reordered.
807 -> IO ()
808iconViewSetReorderable self reorderable =
809  {# call gtk_icon_view_set_reorderable #}
810    (toIconView self)
811    (fromBool reorderable)
812
813-- %hash c:532 d:1d07
814-- | Retrieves whether the user can reorder the list via drag-and-drop. See
815-- 'iconViewSetReorderable'.
816--
817-- * Available since Gtk+ version 2.8
818--
819iconViewGetReorderable :: IconViewClass self => self
820 -> IO Bool -- ^ returns @True@ if the list can be reordered.
821iconViewGetReorderable self =
822  liftM toBool $
823  {# call gtk_icon_view_get_reorderable #}
824    (toIconView self)
825
826#endif
827
828#if GTK_CHECK_VERSION(2,22,0)
829-- | Gets the row in which the item path is currently displayed. Row numbers start at 0.
830--
831-- * Available since Gtk+ version 2.22
832--
833iconViewGetItemRow :: IconViewClass self => self
834                   -> TreePath -- ^ @path@      the 'TreePath' of the item
835                   -> IO Int -- ^ returns   The row in which the item is displayed
836iconViewGetItemRow self path =
837  liftM fromIntegral $
838  withTreePath path $ \path ->
839  {# call gtk_icon_view_get_item_row #}
840    (toIconView self)
841    path
842
843-- | Gets the column in which the item path is currently displayed. Column numbers start at 0.
844--
845-- * Available since Gtk+ version 2.22
846--
847iconViewGetItemColumn :: IconViewClass self => self
848                   -> TreePath -- ^ @path@      the 'TreePath' of the item
849                   -> IO Int -- ^ returns   The column in which the item is displayed
850iconViewGetItemColumn self path =
851  liftM fromIntegral $
852  withTreePath path $ \path ->
853  {# call gtk_icon_view_get_item_column #}
854    (toIconView self)
855    path
856
857#endif
858
859--------------------
860-- Attributes
861
862-- | The ::selection-mode property specifies the selection mode of icon view.
863-- If the mode is 'SelectionMultiple', rubberband selection is enabled, for the
864-- other modes, only keyboard selection is possible.
865--
866-- Default value: 'SelectionSingle'
867--
868iconViewSelectionMode :: IconViewClass self => Attr self SelectionMode
869iconViewSelectionMode = newAttr
870  iconViewGetSelectionMode
871  iconViewSetSelectionMode
872
873-- %hash c:4ce5 d:c77a
874-- | The 'iconViewPixbufColumn' property contains the number of the model column
875-- containing the pixbufs which are displayed. Setting this property to
876-- 'invalidColumnId' turns off the display of pixbufs.
877--
878-- Default value: 'invalidColumnId'
879--
880iconViewPixbufColumn :: IconViewClass self => Attr self (ColumnId row Pixbuf)
881iconViewPixbufColumn = newAttr
882  iconViewGetPixbufColumn
883  iconViewSetPixbufColumn
884
885-- %hash c:702a d:f7ed
886-- | The 'iconViewTextColumn' property contains the number of the model column
887-- containing the texts which are displayed. If this property and the
888-- 'iconViewMarkupColumn' property are both set to 'invalidColumnId', no texts
889-- are displayed.
890--
891-- Default value: 'invalidColumnId'
892--
893iconViewTextColumn :: (IconViewClass self, GlibString string) => Attr self (ColumnId row string)
894iconViewTextColumn = newAttr
895  iconViewGetTextColumn
896  iconViewSetTextColumn
897
898-- %hash c:37cb d:ee83
899-- | The 'iconViewMarkupColumn' property contains the number of the model column
900-- containing markup information to be displayed. If this property and the
901-- 'iconViewTextColumn' property are both set to column numbers, it overrides the text
902-- column. If both are set to 'invalidColumnId', no texts are displayed.
903--
904-- Default value: 'invalidColumnId'
905--
906iconViewMarkupColumn :: (IconViewClass self, GlibString markup) => Attr self (ColumnId row markup)
907iconViewMarkupColumn = newAttr
908  iconViewGetMarkupColumn
909  iconViewSetMarkupColumn
910
911-- %hash c:723d
912-- | The model for the icon view.
913--
914iconViewModel :: (IconViewClass self, TreeModelClass model)
915 => ReadWriteAttr self (Maybe TreeModel) (Maybe model)
916iconViewModel = newAttr
917  iconViewGetModel
918  iconViewSetModel
919
920-- %hash c:6347
921-- | The columns property contains the number of the columns in which the
922-- items should be displayed. If it is -1, the number of columns will be chosen
923-- automatically to fill the available area.
924--
925-- Allowed values: >= -1
926--
927-- Default value: -1
928--
929iconViewColumns :: IconViewClass self => Attr self Int
930iconViewColumns = newAttrFromIntProperty "columns"
931
932-- %hash c:d0fe d:42c5
933-- | The item-width property specifies the width to use for each item. If it
934-- is set to -1, the icon view will automatically determine a suitable item
935-- size.
936--
937-- Allowed values: >= -1
938--
939-- Default value: -1
940--
941iconViewItemWidth :: IconViewClass self => Attr self Int
942iconViewItemWidth = newAttrFromIntProperty "item-width"
943
944-- %hash c:3813 d:23f9
945-- | The spacing property specifies the space which is inserted between the
946-- cells (i.e. the icon and the text) of an item.
947--
948-- Allowed values: >= 0
949--
950-- Default value: 0
951--
952iconViewSpacing :: IconViewClass self => Attr self Int
953iconViewSpacing = newAttrFromIntProperty "spacing"
954
955-- %hash c:6a28 d:8e65
956-- | The row-spacing property specifies the space which is inserted between
957-- the rows of the icon view.
958--
959-- Allowed values: >= 0
960--
961-- Default value: 6
962--
963iconViewRowSpacing :: IconViewClass self => Attr self Int
964iconViewRowSpacing = newAttrFromIntProperty "row-spacing"
965
966-- %hash c:56a d:2971
967-- | The column-spacing property specifies the space which is inserted between
968-- the columns of the icon view.
969--
970-- Allowed values: >= 0
971--
972-- Default value: 6
973--
974iconViewColumnSpacing :: IconViewClass self => Attr self Int
975iconViewColumnSpacing = newAttrFromIntProperty "column-spacing"
976
977-- %hash c:89de d:8e41
978-- | The margin property specifies the space which is inserted at the edges of
979-- the icon view.
980--
981-- Allowed values: >= 0
982--
983-- Default value: 6
984--
985iconViewMargin :: IconViewClass self => Attr self Int
986iconViewMargin = newAttrFromIntProperty "margin"
987
988-- %hash c:b606 d:31c3
989-- | The orientation property specifies how the cells (i.e. the icon and the
990-- text) of the item are positioned relative to each other.
991--
992-- Default value: 'OrientationVertical'
993--
994iconViewOrientation :: IconViewClass self => Attr self Orientation
995iconViewOrientation = newAttrFromEnumProperty "orientation"
996                        {# call pure unsafe gtk_orientation_get_type #}
997
998#if GTK_CHECK_VERSION(2,8,0)
999-- %hash c:f17b d:54d0
1000-- | The reorderable property specifies if the items can be reordered by DND.
1001--
1002-- Default value: @False@
1003--
1004-- * Available since Gtk+ version 2.8
1005--
1006iconViewReorderable :: IconViewClass self => Attr self Bool
1007iconViewReorderable = newAttrFromBoolProperty "reorderable"
1008#endif
1009
1010#if GTK_CHECK_VERSION(2,22,0)
1011-- | The item-orientation property specifies how the cells (i.e. the icon and the text) of the item are
1012-- positioned relative to each other.
1013--
1014-- Default value: 'OrientationVertical'
1015--
1016-- * Available since Gtk+ version 2.22
1017--
1018iconViewItemOrientation :: IconViewClass self => Attr self Orientation
1019iconViewItemOrientation = newAttrFromEnumProperty "item-orientation"
1020                          {# call pure unsafe gtk_orientation_get_type #}
1021#endif
1022
1023--------------------
1024-- Signals
1025
1026-- %hash c:4671 d:af3f
1027-- | New scroll adjustment have been set for this widget.
1028--
1029setIconViewScrollAdjustments :: IconViewClass self => Signal self (Adjustment -> Adjustment -> IO ())
1030setIconViewScrollAdjustments = Signal (connect_OBJECT_OBJECT__NONE "set-scroll-adjustments")
1031
1032-- %hash c:4090 d:af3f
1033-- | A specific element has been activated (by pressing enter or double clicking).
1034--
1035itemActivated :: IconViewClass self => Signal self (TreePath -> IO ())
1036itemActivated = Signal (connect_BOXED__NONE "item-activated" (peekTreePath . castPtr))
1037
1038-- %hash c:6098 d:af3f
1039-- | The selected item changed.
1040--
1041selectionChanged :: IconViewClass self => Signal self (IO ())
1042selectionChanged = Signal (connect_NONE__NONE "selection-changed")
1043
1044#endif
1045