Toc Gallery Index Tree Gtk.Icon_View

Screenshot

No screeshot

Hierarchy

Interfaces

Description

Gtk_Icon_View provides an alternative view on a list model. It displays the model as a grid of icons with labels. Like Gtk_Tree_View, it allows to select one or multiple items (depending on the selection mode, see Set_Selection_Mode). In addition to selection with the arrow keys, Gtk_Icon_View supports rubberband selection, which is controlled by dragging the pointer.

Types

  • type Gtk_Icon_View is access all Gtk_Icon_View_Record'Class;
  • type Gtk_Icon_View_Drop_Position is (No_Drop, Drop_Into, Drop_Left, Drop_Right, Drop_Above, Drop_Below);
    An enum for determining where a dropped item goes. If Drop_Into, then the drop item replaces the item.
  • type Gtk_Icon_View_Record is new Gtk.Container.Gtk_Container_Record with null record;

Subprograms

  • procedure Gtk_New (Icon_View : out Gtk_Icon_View);
    procedure Initialize (Icon_View : access Gtk_Icon_View_Record'Class);
    Creates a new Gtk_Icon_View widget
  • procedure Gtk_New_With_Model (Icon_View : out Gtk_Icon_View; Model : access Gtk.Tree_Model.Gtk_Tree_Model_Record'Class);
    procedure Initialize_With_Model (Icon_View : access Gtk_Icon_View_Record'Class; Model : access Gtk.Tree_Model.Gtk_Tree_Model_Record'Class);
    Creates a new Gtk_Icon_View widget with the model Model.
  • function Get_Type return GType;
    Return the internal type used for a Gtk_Icon_View.
  • procedure Set_Column_Spacing (Icon_View : access Gtk_Icon_View_Record; Column_Spacing : Glib.Gint);
    function Get_Column_Spacing (Icon_View : access Gtk_Icon_View_Record) return Glib.Gint;
    Sets the ::column-spacing property which specifies the space which is inserted between the columns of the icon view.
  • procedure Set_Columns (Icon_View : access Gtk_Icon_View_Record; Columns : Glib.Gint);
    function Get_Columns (Icon_View : access Gtk_Icon_View_Record) return Glib.Gint;
    Sets the ::columns property which determines in how many columns the icons are arranged. If Columns is -1, the number of columns will be chosen automatically to fill the available area.
  • procedure Set_Cursor (Icon_View : access Gtk_Icon_View_Record; Path : Gtk.Tree_Model.Gtk_Tree_Path; Cell : Gtk.Cell_Renderer.Gtk_Cell_Renderer := null; Start_Editing : Boolean := False);
    Sets the current keyboard focus to be at Path, and selects it. This is useful when you want to focus the user's attention on a particular item. If Cell is not null, then focus is given to the cell specified by it. Additionally, if Start_Editing is True, then editing should be started in the specified cell.

    This function is often followed by Grab_Focus in order to give keyboard focus to the widget. Please note that editing can only happen when the widget is realized.

  • procedure Get_Cursor (Icon_View : access Gtk_Icon_View_Record; Path : out Gtk.Tree_Model.Gtk_Tree_Path; Cell : out Gtk.Cell_Renderer.Gtk_Cell_Renderer; Cursor_Is_Set : out Boolean);
    Fills in Path and Cell with the current cursor path and cell. If the cursor isn't currently set, then Ppath will be null. If no cell currently has focus, then Cell will be null. The returned Path must be freed with Gtk.Tree_Model.Path_Free. Cursor_Is_Set is set to True if the cursor is set.
  • procedure Set_Item_Width (Icon_View : access Gtk_Icon_View_Record; Item_Width : Glib.Gint);
    function Get_Item_Width (Icon_View : access Gtk_Icon_View_Record) return Glib.Gint;
    Sets the ::item-width property which specifies the width to use for each item. If it is set to -1, the icon view will automatically determine a suitable item size.
  • procedure Set_Margin (Icon_View : access Gtk_Icon_View_Record; Margin : Glib.Gint);
    function Get_Margin (Icon_View : access Gtk_Icon_View_Record) return Glib.Gint;
    Sets the ::margin property which specifies the space which is inserted at the top, bottom, left and right of the icon view.
  • procedure Set_Orientation (Icon_View : access Gtk_Icon_View_Record; Orientation : Gtk.Enums.Gtk_Orientation);
    function Get_Orientation (Icon_View : access Gtk_Icon_View_Record) return Gtk.Enums.Gtk_Orientation;
    Sets the ::orientation property which determines whether the labels are drawn beside the icons instead of below.
  • procedure Set_Reorderable (Icon_View : access Gtk_Icon_View_Record; Reorderable : Boolean);
    function Get_Reorderable (Icon_View : access Gtk_Icon_View_Record) return Boolean;
    This function is a convenience function to allow you to reorder models that support the Gtk_Tree_Drag_Source interface and the Gtk_Tree_Drag_Dest interface. Both Gtk_Tree_Store and Gtk_List_Store support these. If Reorderable is True, then the user can reorder the model by dragging and dropping rows. The developer can listen to these changes by connecting to the model's row_inserted and row_deleted signals.

    This function does not give you any degree of control over the order -- any reordering is allowed. If more control is needed, you should probably handle drag and drop manually.

  • procedure Set_Row_Spacing (Icon_View : access Gtk_Icon_View_Record; Row_Spacing : Glib.Gint);
    function Get_Row_Spacing (Icon_View : access Gtk_Icon_View_Record) return Glib.Gint;
    Sets the ::row-spacing property which specifies the space which is inserted between the rows of the icon view.
  • procedure Set_Spacing (Icon_View : access Gtk_Icon_View_Record; Spacing : Glib.Gint);
    function Get_Spacing (Icon_View : access Gtk_Icon_View_Record) return Glib.Gint;
    Sets the ::spacing property which specifies the space which is inserted between the cells (i.e. the icon and the text) of an item.
  • procedure Item_Activated (Icon_View : access Gtk_Icon_View_Record; Path : Gtk.Tree_Model.Gtk_Tree_Path);
    Activates the item determined by Path.
  • Scrolling

  • procedure Get_Visible_Range (Icon_View : access Gtk_Icon_View_Record; Start_Path : out Gtk.Tree_Model.Gtk_Tree_Path; End_Path : out Gtk.Tree_Model.Gtk_Tree_Path);
    Sets Start_Path and End_Path to be the first and last visible path. Note that there may be invisible paths in between. Both paths should be freed with Path_Free after use.
  • procedure Scroll_To_Path (Icon_View : access Gtk_Icon_View_Record; Path : Gtk.Tree_Model.Gtk_Tree_Path; Use_Align : Boolean := True; Row_Align : Glib.Gfloat := 0.5; Col_Align : Glib.Gfloat := 0.0);
    Moves the alignments of Icon_View to the position specified by Path. Row_Align determines where the row is placed, and Col_Align determines where column is placed. Both are expected to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means center.

    If Use_Align is False, then the alignment arguments are ignored, and the tree does the minimum amount of work to scroll the item onto the screen. This means that the item will be scrolled to the edge closest to its current position. If the item is currently visible on the screen, nothing is done.

    This function only works if the model is set, and Path is a valid row on the model. If the model changes before the Icon_View is realized, the centered path will be modified to reflect this change.

  • Tree Model

  • procedure Set_Model (Icon_View : access Gtk_Icon_View_Record; Model : Gtk.Tree_Model.Gtk_Tree_Model := null);
    function Get_Model (Icon_View : access Gtk_Icon_View_Record) return Gtk.Tree_Model.Gtk_Tree_Model;
    Sets the model for a Gtk_Icon_View. If the Icon_View already has a model set, it will remove it before setting the new model. If Model is null, then it will unset the old model.
  • procedure Set_Text_Column (Icon_View : access Gtk_Icon_View_Record; Column : Glib.Gint);
    function Get_Text_Column (Icon_View : access Gtk_Icon_View_Record) return Glib.Gint;
    Sets the column with text for Icon_View to be Column. The text column must be of type GType_String.
  • procedure Set_Pixbuf_Column (Icon_View : access Gtk_Icon_View_Record; Column : Glib.Gint);
    function Get_Pixbuf_Column (Icon_View : access Gtk_Icon_View_Record) return Glib.Gint;
    Sets the column with pixbufs for Icon_View to be Column. The pixbuf column must be of type Gdk.Pixbuf.Get_Type
  • procedure Set_Markup_Column (Icon_View : access Gtk_Icon_View_Record; Column : Glib.Gint);
    function Get_Markup_Column (Icon_View : access Gtk_Icon_View_Record) return Glib.Gint;
    Sets the column with markup information for Icon_View to be Column. The markup column must be of type GType_String. If the markup column is set to something, it overrides the text column set by Set_Text_Column.
  • function Get_Path_At_Pos (Icon_View : access Gtk_Icon_View_Record; X : Glib.Gint; Y : Glib.Gint) return Gtk.Tree_Model.Gtk_Tree_Path;
    Finds the path at the point (X, Y), relative to widget coordinates. See Get_Item_At_Pos, if you are also interested in the cell at the specified position.
  • procedure Get_Item_At_Pos (Icon_View : access Gtk_Icon_View_Record; X : Gint; Y : Gint; Path : out Gtk.Tree_Model.Gtk_Tree_Path; Cell : out Gtk.Cell_Renderer.Gtk_Cell_Renderer; Has_Item : out Boolean);
    Finds the path at the point (X, Y), relative to widget coordinates. In contrast to Get_Path_At_Pos, this function also obtains the cell at the specified position. The returned path should be freed with Path_Free. Has_Item is set to True if an item exists at the specified position.
  • Selection

  • procedure Set_Selection_Mode (Icon_View : access Gtk_Icon_View_Record; Mode : Gtk.Enums.Gtk_Selection_Mode);
    function Get_Selection_Mode (Icon_View : access Gtk_Icon_View_Record) return Gtk.Enums.Gtk_Selection_Mode;
    Sets the selection mode of the Icon_View.
  • procedure Select_All (Icon_View : access Gtk_Icon_View_Record);
    procedure Unselect_All (Icon_View : access Gtk_Icon_View_Record);
    Selects all the icons. Icon_View must has its selection mode set to Selection_Multiple
  • procedure Select_Path (Icon_View : access Gtk_Icon_View_Record; Path : Gtk.Tree_Model.Gtk_Tree_Path);
    procedure Unselect_Path (Icon_View : access Gtk_Icon_View_Record; Path : Gtk.Tree_Model.Gtk_Tree_Path);
    Selects the row at Path.
  • function Get_Selected_Items (Icon_View : access Gtk_Icon_View_Record) return Gtk.Tree_Model.Gtk_Tree_Path_List.Glist;
    Creates a list of paths of all selected items. Additionally, if you are planning on modifying the model after calling this function, you may want to convert the returned list into a list of Gtk_Tree_Row_Reference. To free the returend value, use: Foreach (List, Gtk.Tree_Model.Path_Free, Null); Free (List);
  • function Path_Is_Selected (Icon_View : access Gtk_Icon_View_Record; Path : Gtk.Tree_Model.Gtk_Tree_Path) return Boolean;
    Returns True if the icon pointed to by Path is currently selected. If Path does not point to a valid location, False is returned.
  • Drag and drop

  • function Create_Drag_Icon (Icon_View : access Gtk_Icon_View_Record; Path : Gtk.Tree_Model.Gtk_Tree_Path) return Gdk.Gdk_Pixmap;
    Creates a Gdk_Pixmap representation of the item at Path. This image is used for a drag icon. The returned value must be Unref'd by the caller.
  • procedure Enable_Model_Drag_Dest (Icon_View : access Gtk_Icon_View_Record; Targets : Gtk.Selection.Target_Entry_Array; Actions : Gdk.Dnd.Drag_Action);
    procedure Unset_Model_Drag_Dest (Icon_View : access Gtk_Icon_View_Record);
    Turns Icon_view into a drop destination for automatic DND. Targets is the list of targets that the drag will support.
  • procedure Enable_Model_Drag_Source (Icon_View : access Gtk_Icon_View_Record; Start_Button_Mask : Gdk.Types.Gdk_Modifier_Type; Targets : Gtk.Selection.Target_Entry_Array; Actions : Gdk.Dnd.Drag_Action);
    procedure Unset_Model_Drag_Source (Icon_View : access Gtk_Icon_View_Record);
    Turns Icon_view into a drag source for automatic DND. Start_Button_Mask is the allowed buttons to start drag.
  • procedure Get_Dest_Item_At_Pos (Icon_View : access Gtk_Icon_View_Record; Drag_X : Glib.Gint; Drag_Y : Glib.Gint; Path : out Gtk.Tree_Model.Gtk_Tree_Path; Pos : out Gtk_Icon_View_Drop_Position; Has_Item : out Boolean);
    Determines the destination item for a given position. Return value: whether there is an item at the given position.
  • procedure Set_Drag_Dest_Item (Icon_View : access Gtk_Icon_View_Record; Path : Gtk.Tree_Model.Gtk_Tree_Path; Pos : Gtk_Icon_View_Drop_Position);
    procedure Get_Drag_Dest_Item (Icon_View : access Gtk_Icon_View_Record; Path : out Gtk.Tree_Model.Gtk_Tree_Path; Pos : out Gtk_Icon_View_Drop_Position);
    Sets the item that is highlighted for feedback.
  • Interfaces

    This class implements several interfaces. See Glib.Types
  • function "+" (Widget : access Gtk_Icon_View_Record'Class) return Gtk.Cell_Layout.Gtk_Cell_Layout renames Implements_Cell_Layout.To_Interface;
    function "-" (Interf : Gtk.Cell_Layout.Gtk_Cell_Layout) return Gtk_Icon_View renames Implements_Cell_Layout.To_Object;
    Converts to and from the Gtk_Cell_Layout interface

Signals

Properties

  • Column_Spacing_Property
    Int
    Space which is inserted between grid column
  • Columns_Property
    Int
    Number of columns to display
  • Item_Width_Property
    Int
    The width used for each item
  • Margin_Property
    Int
    Space which is inserted at the edges of the icon view
  • Markup_Column_Property
    Int
    Model column used to retrieve the text if using Pango markup
  • Model_Property
    Object
    The model for the icon view
  • Orientation_Property
    Enum
    How the text and icon of each item are positioned relative to
  • Pixbuf_Column_Property
    Int
    Model column used to retrieve the icon pixbuf from
  • Reorderable_Property
    Boolean
    View is reorderable
  • Row_Spacing_Property
    Int
    Space which is inserted between grid rows
  • Selection_Mode_Property
    Enum
    The selection mode
  • Spacing_Property
    Int
    Space which is inserted between cells of an item
  • Text_Column_Property
    Int
    Model column used to retrieve the text from

Testgtk source code

This code is part of testgtk, a demo application packaged with GtkAda. Testgtk demonstrates the various widgets of GtkAda
----------------------------------------------------------------------- -- GtkAda - Ada95 binding for the Gimp Toolkit -- -- -- -- Copyright (C) 2006, AdaCore -- -- -- -- This library is free software; you can redistribute it and/or -- -- modify it under the terms of the GNU General Public -- -- License as published by the Free Software Foundation; either -- -- version 2 of the License, or (at your option) any later version. -- -- -- -- This 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 -- -- General Public License for more details. -- -- -- -- You should have received a copy of the GNU General Public -- -- License along with this library; if not, write to the -- -- Free Software Foundation, Inc., 59 Temple Place - Suite 330, -- -- Boston, MA 02111-1307, USA. -- -- -- -- -- -- -- -- -- -- ----------------------------------------------------------------------- with Gdk.Dnd; use Gdk.Dnd; with Gdk.Pixbuf; use Gdk.Pixbuf; with Gdk.Types; use Gdk.Types; with Glib; use Glib; with Glib.Error; use Glib.Error; with Glib.Object; use Glib.Object; with Glib.Properties; use Glib.Properties; with Glib.Values; use Glib.Values; with Gtkada.Handlers; use Gtkada.Handlers; with Gtk.Arguments; use Gtk.Arguments; with Gtk.Cell_Layout; use Gtk.Cell_Layout; with Gtk.Cell_Renderer; use Gtk.Cell_Renderer; with Gtk.Cell_Renderer_Pixbuf; use Gtk.Cell_Renderer_Pixbuf; with Gtk.Cell_Renderer_Text; use Gtk.Cell_Renderer_Text; with Gtk.Cell_Renderer_Toggle; use Gtk.Cell_Renderer_Toggle; with Gtk.Enums; use Gtk.Enums; with Gtk.Frame; use Gtk.Frame; with Gtk.Icon_View; use Gtk.Icon_View; with Gtk.List_Store; use Gtk.List_Store; with Gtk.Scrolled_Window; use Gtk.Scrolled_Window; with Gtk.Selection; use Gtk.Selection; with Gtk.Tree_Model; use Gtk.Tree_Model; with Interfaces.C.Strings; use Interfaces.C.Strings; package body Create_Icon_View is Item_Targets : constant Target_Entry_Array := (1 => (Target => New_String ("GTK_TREE_MODEL_ROW"), Flags => Target_Same_App, Info => 0)); procedure Fill_Model (List : Gtk_List_Store); -- Fill the contents of List procedure Toggled (Model : access GObject_Record'Class; Params : Glib.Values.GValues); -- Called when one of the toggle buttons is clicked on. This performs the -- actual toggling. ---------- -- Help -- ---------- function Help return String is begin return "A @bGtk_Icon_View@B is a widget which displays a list of icons" & " in a grid. Its data is stored in a @bGtk_Tree_Model@B." & ASCII.LF & "In this demo, @bdrag-and-drop@B is activated so that icons can be" & " moved from one location to another." & ASCII.LF & "This example also shows how to make a toggle button editable within" & " an icon view."; end Help; ------------- -- Toggled -- ------------- procedure Toggled (Model : access GObject_Record'Class; Params : Glib.Values.GValues) is M : constant Gtk_List_Store := Gtk_List_Store (Model); Path_String : constant String := To_String (Params, 1); Path : constant Gtk_Tree_Path := Gtk_New (Path_String); Iter : constant Gtk_Tree_Iter := Get_Iter (M, Path); Value : constant Boolean := Get_Boolean (M, Iter, 2); begin Set (M, Iter, 2, not Value); Path_Free (Path); end Toggled; ---------------- -- Fill_Model -- ---------------- procedure Fill_Model (List : Gtk_List_Store) is Pixbuf : Gdk_Pixbuf; Error : GError; Iter : Gtk_Tree_Iter; begin Gdk_New_From_File (Pixbuf, Filename => "gnome-textfile.png", Error => Error); Prepend (List, Iter); Set (List, Iter, 0, Pixbuf); Set (List, Iter, 1, "Really Really" & ASCII.LF & " Really really looooooooong item name"); Set (List, Iter, 2, True); for J in 0 .. 9 loop Prepend (List, Iter); Set (List, Iter, 0, Pixbuf); Set (List, Iter, 1, "Icon" & J'Img); Set (List, Iter, 2, True); end loop; end Fill_Model; --------- -- Run -- --------- procedure Run (Frame : access Gtk.Frame.Gtk_Frame_Record'Class) is Scrolled : Gtk_Scrolled_Window; View : Gtk_Icon_View; List : Gtk_List_Store; Text : Gtk_Cell_Renderer_Text; Toggle : Gtk_Cell_Renderer_Toggle; Pixbuf : Gtk_Cell_Renderer_Pixbuf; begin Set_Label (Frame, "Icon View"); Gtk_New (Scrolled); Add (Frame, Scrolled); Gtk_New (View); Add (Scrolled, View); Set_Selection_Mode (View, Selection_Multiple); Gtk_New (List, (0 => Gdk.Pixbuf.Get_Type, -- Associated pixbuf 1 => GType_String, -- Text for the icon 2 => GType_Boolean)); -- Toggle activated ? Set_Model (View, Gtk_Tree_Model (List)); Fill_Model (List); Gtk_New (Toggle); Pack_Start (+View, Toggle, Expand => False); Set_Property (Toggle, Activatable_Property, True); Add_Attribute (+View, Toggle, "active", 2); Object_Callback.Object_Connect (Toggle, "toggled", Toggled'Access, List); -- Connect "toggled" signal Gtk_New (Pixbuf); Pack_Start (+View, Pixbuf, Expand => False); Set_Property (Pixbuf, Follow_State_Property, True); Add_Attribute (+View, Pixbuf, "pixbuf", 0); Gtk_New (Text); Pack_Start (+View, Text, Expand => False); Set_Property (Text, Editable_Property, True); Set_Property (Text, Xalign_Property, 0.5); -- Set_Property (Text, Wrap_Mode_Property, Wrap_Word_Char); Set_Property (Text, Wrap_Width_Property, 100); Add_Attribute (+View, Text, "text", 1); -- Connect "edited" signal -- Allow drag-and-drop of icons Enable_Model_Drag_Source (View, Start_Button_Mask => Button1_Mask, Targets => Item_Targets, Actions => Action_Move); Enable_Model_Drag_Dest (View, Targets => Item_Targets, Actions => Action_Move); Show_All (Frame); end Run; end Create_Icon_View;

Alphabetical Index