1
-----------------------------------------------------------------------
2
-- GtkAda - Ada95 binding for the Gimp Toolkit --
4
-- Copyright (C) 2006, AdaCore --
6
-- This library is free software; you can redistribute it and/or --
7
-- modify it under the terms of the GNU General Public --
8
-- License as published by the Free Software Foundation; either --
9
-- version 2 of the License, or (at your option) any later version. --
11
-- This library is distributed in the hope that it will be useful, --
12
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
13
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
14
-- General Public License for more details. --
16
-- You should have received a copy of the GNU General Public --
17
-- License along with this library; if not, write to the --
18
-- Free Software Foundation, Inc., 59 Temple Place - Suite 330, --
19
-- Boston, MA 02111-1307, USA. --
21
-----------------------------------------------------------------------
23
with Gdk.Dnd; use Gdk.Dnd;
24
with Gdk.Pixbuf; use Gdk.Pixbuf;
25
with Gdk.Types; use Gdk.Types;
27
with Glib.Error; use Glib.Error;
28
with Glib.Object; use Glib.Object;
29
with Glib.Properties; use Glib.Properties;
30
with Glib.Values; use Glib.Values;
31
with Gtkada.Handlers; use Gtkada.Handlers;
32
with Gtk.Arguments; use Gtk.Arguments;
33
with Gtk.Cell_Layout; use Gtk.Cell_Layout;
34
with Gtk.Cell_Renderer; use Gtk.Cell_Renderer;
35
with Gtk.Cell_Renderer_Pixbuf; use Gtk.Cell_Renderer_Pixbuf;
36
with Gtk.Cell_Renderer_Text; use Gtk.Cell_Renderer_Text;
37
with Gtk.Cell_Renderer_Toggle; use Gtk.Cell_Renderer_Toggle;
38
with Gtk.Enums; use Gtk.Enums;
39
with Gtk.Frame; use Gtk.Frame;
40
with Gtk.Icon_View; use Gtk.Icon_View;
41
with Gtk.List_Store; use Gtk.List_Store;
42
with Gtk.Scrolled_Window; use Gtk.Scrolled_Window;
43
with Gtk.Selection; use Gtk.Selection;
44
with Gtk.Tree_Model; use Gtk.Tree_Model;
45
with Interfaces.C.Strings; use Interfaces.C.Strings;
47
package body Create_Icon_View is
49
Item_Targets : constant Target_Entry_Array :=
50
(1 => (Target => New_String ("GTK_TREE_MODEL_ROW"),
51
Flags => Target_Same_App,
54
procedure Fill_Model (List : Gtk_List_Store);
55
-- Fill the contents of List
58
(Model : access GObject_Record'Class;
59
Params : Glib.Values.GValues);
60
-- Called when one of the toggle buttons is clicked on. This performs the
67
function Help return String is
69
return "A @bGtk_Icon_View@B is a widget which displays a list of icons"
70
& " in a grid. Its data is stored in a @bGtk_Tree_Model@B."
72
& "In this demo, @bdrag-and-drop@B is activated so that icons can be"
73
& " moved from one location to another."
75
& "This example also shows how to make a toggle button editable within"
84
(Model : access GObject_Record'Class;
85
Params : Glib.Values.GValues)
87
M : constant Gtk_List_Store := Gtk_List_Store (Model);
88
Path_String : constant String := To_String (Params, 1);
89
Path : constant Gtk_Tree_Path := Gtk_New (Path_String);
90
Iter : constant Gtk_Tree_Iter := Get_Iter (M, Path);
91
Value : constant Boolean := Get_Boolean (M, Iter, 2);
93
Set (M, Iter, 2, not Value);
101
procedure Fill_Model (List : Gtk_List_Store) is
104
Iter : Gtk_Tree_Iter;
107
(Pixbuf, Filename => "gnome-textfile.png", Error => Error);
109
Prepend (List, Iter);
110
Set (List, Iter, 0, Pixbuf);
111
Set (List, Iter, 1, "Really Really" & ASCII.LF
112
& " Really really looooooooong item name");
113
Set (List, Iter, 2, True);
116
Prepend (List, Iter);
117
Set (List, Iter, 0, Pixbuf);
118
Set (List, Iter, 1, "Icon" & J'Img);
119
Set (List, Iter, 2, True);
127
procedure Run (Frame : access Gtk.Frame.Gtk_Frame_Record'Class) is
128
Scrolled : Gtk_Scrolled_Window;
129
View : Gtk_Icon_View;
130
List : Gtk_List_Store;
131
Text : Gtk_Cell_Renderer_Text;
132
Toggle : Gtk_Cell_Renderer_Toggle;
133
Pixbuf : Gtk_Cell_Renderer_Pixbuf;
135
Set_Label (Frame, "Icon View");
138
Add (Frame, Scrolled);
141
Add (Scrolled, View);
142
Set_Selection_Mode (View, Selection_Multiple);
146
(0 => Gdk.Pixbuf.Get_Type, -- Associated pixbuf
147
1 => GType_String, -- Text for the icon
148
2 => GType_Boolean)); -- Toggle activated ?
149
Set_Model (View, Gtk_Tree_Model (List));
154
Pack_Start (+View, Toggle, Expand => False);
155
Set_Property (Toggle, Activatable_Property, True);
156
Add_Attribute (+View, Toggle, "active", 2);
157
Object_Callback.Object_Connect
158
(Toggle, "toggled", Toggled'Access, List);
160
-- Connect "toggled" signal
163
Pack_Start (+View, Pixbuf, Expand => False);
164
Set_Property (Pixbuf, Follow_State_Property, True);
165
Add_Attribute (+View, Pixbuf, "pixbuf", 0);
168
Pack_Start (+View, Text, Expand => False);
169
Set_Property (Text, Editable_Property, True);
170
Set_Property (Text, Xalign_Property, 0.5);
171
-- Set_Property (Text, Wrap_Mode_Property, Wrap_Word_Char);
172
Set_Property (Text, Wrap_Width_Property, 100);
173
Add_Attribute (+View, Text, "text", 1);
174
-- Connect "edited" signal
176
-- Allow drag-and-drop of icons
177
Enable_Model_Drag_Source
179
Start_Button_Mask => Button1_Mask,
180
Targets => Item_Targets,
181
Actions => Action_Move);
182
Enable_Model_Drag_Dest
184
Targets => Item_Targets,
185
Actions => Action_Move);
190
end Create_Icon_View;