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 Glib;                use Glib;
25with Glib.Values;         use Glib.Values;
26with Gtk.Box;             use Gtk.Box;
27with Gtk.Button;          use Gtk.Button;
28with Gtk.Enums;           use Gtk.Enums;
29with Gtk.Frame;           use Gtk.Frame;
30--  with Gtk.Scrolled_Window; use Gtk.Scrolled_Window;
31with Gtk.Stack;           use Gtk.Stack;
32with Gtk.Stack_Switcher;  use Gtk.Stack_Switcher;
33with Gtk.Text_Buffer;     use Gtk.Text_Buffer;
34with Gtk.Text_View;       use Gtk.Text_View;
35with Gtk.Widget;          use Gtk.Widget;
36
37package body Create_Stack is
38
39   ----------
40   -- Help --
41   ----------
42
43   function Help return String is
44   begin
45      return "A @bGtk_Stack@B is a widget that only shows one of its children"
46         & " at a time." & ASCII.LF
47         & "It can be combined with a @bGtk_Stack_Switcher@B to allow"
48         & " interactive switching.";
49   end Help;
50
51   ---------
52   -- Run --
53   ---------
54
55   procedure Run (Frame : access Gtk.Frame.Gtk_Frame_Record'Class) is
56      Box      : Gtk_Box;
57      Switcher : Gtk_Stack_Switcher;
58      Stack    : Gtk_Stack;
59      W1       : Gtk_Text_View;
60      W2       : Gtk_Button;
61      --  Scrolled : Gtk_Scrolled_Window;
62      V        : GValue;
63   begin
64      Gtk_New (Box, Orientation_Vertical, 0);
65      Frame.Add (Box);
66
67      Gtk_New (Switcher);
68      Box.Pack_Start (Switcher, Expand => False, Fill => False);
69
70      Gtk_New (Stack);
71      Stack.Set_Transition_Duration (1500);  --  slower to better see them
72      Stack.Set_Halign (Align_Start);
73      Box.Add (Stack);
74
75      Switcher.Set_Stack (Stack);
76
77      Gtk_New (W1);
78      W1.Get_Buffer.Set_Text ("This is a test");
79      Stack.Add_Titled (W1, "Name:1", "Title:1");
80
81      Gtk_New (W2, "A label");
82      Stack.Add (W2);
83
84      Init (V, GType_String);
85      Set_String (V, "2");
86      Stack.Child_Set_Property (W2, "name", V);
87      Stack.Child_Set_Property (W2, "title", V);
88      Unset (V);
89
90      Init (V, GType_Boolean);
91      Set_Boolean (V, True);
92      Stack.Child_Set_Property (W2, "needs-attention", V);  --  See CSS file
93      Unset (V);
94
95      Frame.Show_All;
96   end Run;
97end Create_Stack;
98