1------------------------------------------------------------------------------
2--               GtkAda - Ada95 binding for the Gimp Toolkit                --
3--                                                                          --
4--                     Copyright (C) 2014-2015, AdaCore                     --
5--                                                                          --
6-- This library is free software;  you can redistribute it and/or modify it --
7-- under terms of the  GNU General Public License  as published by the Free --
8-- Software  Foundation;  either version 3,  or (at your  option) any later --
9-- version. This library is distributed in the hope that it will be useful, --
10-- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- --
11-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            --
12--                                                                          --
13-- As a special exception under Section 7 of GPL version 3, you are granted --
14-- additional permissions described in the GCC Runtime Library Exception,   --
15-- version 3.1, as published by the Free Software Foundation.               --
16--                                                                          --
17-- You should have received a copy of the GNU General Public License and    --
18-- a copy of the GCC Runtime Library Exception along with this program;     --
19-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
20-- <http://www.gnu.org/licenses/>.                                          --
21--                                                                          --
22------------------------------------------------------------------------------
23
24with Gdk.RGBA;                 use Gdk.RGBA;
25with Gdk.Types;                use Gdk.Types;
26with Gtk.Enums;                use Gtk.Enums;
27with Gtk.Scrolled_Window;      use Gtk.Scrolled_Window;
28with Gtkada.Canvas_View;       use Gtkada.Canvas_View;
29with Gtkada.Canvas_View.Views; use Gtkada.Canvas_View.Views;
30with Gtkada.Style;             use Gtkada.Style;
31with Pango.Font;               use Pango.Font;
32
33package body Create_Canvas_View_Edit is
34
35   function On_Item_Event_Zoom is new On_Item_Event_Zoom_Generic
36      (Modifier => Mod1_Mask);
37   function On_Item_Event_Key_Navigate is new
38      On_Item_Event_Key_Navigate_Generic (Modifier => 0);
39
40   ----------
41   -- Help --
42   ----------
43
44   function Help return String is
45   begin
46      return "This demo shows how to implement in-place editing of items"
47         & ASCII.LF
48         & "Double-clicking on any text will display a popup window with a"
49         & " text editor. Pressing ctrl-enter in that editor will change the"
50         & " text of the item. Pressing escape (or clicking anywhere) will"
51         & " simply close the popup";
52   end Help;
53
54   ---------
55   -- Run --
56   ---------
57
58   procedure Run (Frame : access Gtk.Frame.Gtk_Frame_Record'Class) is
59      Scrolled    : Gtk_Scrolled_Window;
60      Canvas      : Canvas_View;
61      Model       : List_Canvas_Model;
62      Text        : Editable_Text_Item;
63      NText       : Text_Item;
64      Rect        : Rect_Item;
65      White, Font : Drawing_Style;
66   begin
67      Font := Gtk_New
68        (Stroke => Null_RGBA,
69         Font   => (Name   => From_String ("sans 10"),
70                    Color  => Black_RGBA,
71                    others => <>));
72
73      White := Gtk_New
74        (Fill  => Create_Rgba_Pattern ((1.0, 1.0, 1.0, 1.0)));
75
76      Gtk_New (Model);
77
78      Rect := Gtk_New_Rect (White);
79      Rect.Set_Position ((50.0, 50.0));
80      Model.Add (Rect);
81
82      Text := Gtk_New_Editable_Text (Font, "Line 1");
83      Rect.Add_Child (Text);
84
85      Text := Gtk_New_Editable_Text (Font, "Line 2");
86      Rect.Add_Child (Text);
87
88      Text := Gtk_New_Editable_Text (Font, "Line 3");
89      Rect.Add_Child (Text);
90
91      NText := Gtk_New_Text (Font, "Non editable");
92      Rect.Add_Child (NText);
93
94      Rect := Gtk_New_Rect (White, 50.0, 50.0);
95      Rect.Set_Position ((550.0, 550.0));
96      Model.Add (Rect);
97
98      Text := Gtk_New_Editable_Text (Font, "Legend");
99      Text.Set_Position ((200.0, 50.0));
100      Model.Add (Text);
101
102      Gtk_New (Scrolled);
103      Scrolled.Set_Policy (Policy_Automatic, Policy_Automatic);
104      Frame.Add (Scrolled);
105
106      Gtk_New (Canvas, Model);
107      Unref (Model);
108      Scrolled.Add (Canvas);
109
110      Canvas.On_Item_Event (On_Item_Event_Select'Access);
111      Canvas.On_Item_Event (On_Item_Event_Move_Item'Access);
112      Canvas.On_Item_Event (On_Item_Event_Scroll_Background'Access);
113      Canvas.On_Item_Event (On_Item_Event_Edit'Access);
114      Canvas.On_Item_Event (On_Item_Event_Zoom'Access);
115      Canvas.On_Item_Event (On_Item_Event_Key_Navigate'Access);
116
117      Frame.Show_All;
118   end Run;
119
120end Create_Canvas_View_Edit;
121