File: create_splittable.adb

package info (click to toggle)
libgtkada2 2.8.1-6lenny3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 13,496 kB
  • ctags: 3,886
  • sloc: ada: 103,189; ansic: 45,411; perl: 5,500; sh: 2,812; makefile: 1,169; xml: 19
file content (254 lines) | stat: -rw-r--r-- 8,596 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
-----------------------------------------------------------------------
--          GtkAda - Ada95 binding for the Gimp Toolkit              --
--                                                                   --
--                     Copyright (C) 2003                            --
--        Emmanuel Briot, Joel Brobecker and Arnaud Charlet          --
--                     Copyright (C) 2004-2005                       --
--                           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.                                       --
--                                                                   --
-- As a special exception, if other files instantiate generics from  --
-- this unit, or you link this unit with other files to produce an   --
-- executable, this  unit  does not  by itself cause  the resulting  --
-- executable to be covered by the GNU General Public License. This  --
-- exception does not however invalidate any other reasons why the   --
-- executable file  might be covered by the  GNU Public License.     --
-----------------------------------------------------------------------

with Gtk;                use Gtk;
with Gtk.Box;            use Gtk.Box;
with Gtk.Button;         use Gtk.Button;
with Gtk.Frame;          use Gtk.Frame;
with Gtk.Widget;         use Gtk.Widget;
with Gtkada.Multi_Paned; use Gtkada.Multi_Paned;
with Gtk.Toolbar;        use Gtk.Toolbar;
with Gtkada.Handlers;    use Gtkada.Handlers;
with Gtk.Vbutton_Box;    use Gtk.Vbutton_Box;
with Gtk.Toggle_Button;  use Gtk.Toggle_Button;
with Gtk.Enums;          use Gtk.Enums;

package body Create_Splittable is

   function Create_Child
      (Bar : Gtk_Toolbar; Title : String) return Gtk_Widget;
   procedure On_Destroy (Button : access Gtk_Widget_Record'Class);
   procedure On_Toggle  (Button : access Gtk_Widget_Record'Class);
   procedure On_Resize  (Button : access Gtk_Widget_Record'Class);
   procedure On_Split_V (Button : access Gtk_Widget_Record'Class);
   procedure On_Split_H (Button : access Gtk_Widget_Record'Class);
   procedure On_Fixed   (Button : access Gtk_Widget_Record'Class);
   procedure On_Opaque  (Button : access Gtk_Widget_Record'Class);

   Pane   : Gtkada_Multi_Paned;
   Item   : Natural := 6;
   Opaque : Boolean := False;

   ----------
   -- Help --
   ----------

   function Help return String is
   begin
      return "A Gtkada-specific widget, where children can be resized"
        & " interactively by the user, as well as splitted.";
   end Help;

   ---------------
   -- On_Opaque --
   ---------------

   procedure On_Opaque  (Button : access Gtk_Widget_Record'Class) is
      pragma Unreferenced (Button);
   begin
      Opaque := not Opaque;
      Set_Opaque_Resizing (Pane, Opaque);
   end On_Opaque;

   ----------------
   -- On_Destroy --
   ----------------

   procedure On_Destroy (Button : access Gtk_Widget_Record'Class) is
   begin
      Destroy (Button);
   end On_Destroy;

   ---------------
   -- On_Toggle --
   ---------------

   procedure On_Toggle (Button : access Gtk_Widget_Record'Class) is
   begin
      if Visible_Is_Set (Button) then
         Hide (Button);
      else
         Show (Button);
      end if;
   end On_Toggle;

   ---------------
   -- On_Resize --
   ---------------

   procedure On_Resize (Button : access Gtk_Widget_Record'Class) is
   begin
      Set_Size (Pane, Button, 100, 100);
   end On_Resize;

   ----------------
   -- On_Split_V --
   ----------------

   procedure On_Split_V (Button : access Gtk_Widget_Record'Class) is
      Child : constant Gtk_Widget := Create_Child (null, Integer'Image (Item));
   begin
      Item := Item + 1;
      Split (Pane, Button, Child, Orientation_Vertical);
   end On_Split_V;

   ----------------
   -- On_Split_H --
   ----------------

   procedure On_Split_H (Button : access Gtk_Widget_Record'Class) is
      Child : constant Gtk_Widget := Create_Child (null, Integer'Image (Item));
   begin
      Item := Item + 1;
      Split (Pane, Button, Child, Orientation_Horizontal);
   end On_Split_H;

   --------------
   -- On_Fixed --
   --------------

   procedure On_Fixed (Button : access Gtk_Widget_Record'Class) is
   begin
      Set_Size (Pane, Button,
                Get_Allocation_Width (Button),
                Get_Allocation_Height (Button),
                Fixed_Size => True);
   end On_Fixed;

   ------------------
   -- Create_Child --
   ------------------

   function Create_Child
      (Bar : Gtk_Toolbar; Title : String) return Gtk_Widget
   is
      Frame  : Gtk_Frame;
      Box    : Gtk_Vbutton_Box;
      Button : Gtk_Button;
      Item   : Gtk_Button;
   begin
      Gtk_New (Frame);

      Gtk_New (Box);
      Add (Frame, Box);
      Set_Layout (Box, Buttonbox_Start);

      Gtk_New (Button, "Destroy_" & Title);
      Pack_Start (Box, Button, Expand => False);
      Widget_Callback.Object_Connect
        (Button, "clicked",
         Widget_Callback.To_Marshaller (On_Destroy'Unrestricted_Access),
         Frame);

      Gtk_New (Button, "Resize_" & Title);
      Pack_Start (Box, Button, Expand => False);
      Widget_Callback.Object_Connect
        (Button, "clicked",
         Widget_Callback.To_Marshaller (On_Resize'Unrestricted_Access),
         Frame);

      Gtk_New (Button, "Split_V " & Title);
      Pack_Start (Box, Button, Expand => False);
      Widget_Callback.Object_Connect
        (Button, "clicked",
         Widget_Callback.To_Marshaller (On_Split_V'Unrestricted_Access),
         Frame);

      Gtk_New (Button, "Split_H " & Title);
      Pack_Start (Box, Button, Expand => False);
      Widget_Callback.Object_Connect
        (Button, "clicked",
         Widget_Callback.To_Marshaller (On_Split_H'Unrestricted_Access),
         Frame);

      Gtk_New (Button, "Fixed_Size " & Title);
      Pack_Start (Box, Button, Expand => False);
      Widget_Callback.Object_Connect
        (Button, "clicked",
         Widget_Callback.To_Marshaller (On_Fixed'Unrestricted_Access),
         Frame);

      if Bar /= null then
         Gtk_New (Item, "Toggle_" & Title);
         Add (Bar, Item);
         Widget_Callback.Object_Connect
           (Item, "clicked",
            Widget_Callback.To_Marshaller (On_Toggle'Unrestricted_Access),
            Frame);
      end if;

      Show_All (Frame);
      return Gtk_Widget (Frame);
   end Create_Child;

   ---------
   -- Run --
   ---------

   procedure Run (Frame : access Gtk.Frame.Gtk_Frame_Record'Class) is
      Button, Button1, Button2, Button3, Button4 : Gtk_Widget;
      Bar    : Gtk_Toolbar;
      Box    : Gtk_Box;
      Toggle : Gtk_Toggle_Button;
   begin
      Gtk_New_Vbox (Box, Homogeneous => False);
      Add (Frame, Box);

      Gtk_New (Bar);
      Pack_Start (Box, Bar, Expand => False);

      Gtk_New (Toggle, "Opaque Resizing");
      Pack_Start (Box, Toggle, Expand => False);
      Widget_Callback.Connect (Toggle, "toggled", On_Opaque'Access);

      Gtk_New (Pane);
      Pack_Start (Box, Pane, Expand => True, Fill => True);

      Button1 := Create_Child (Bar, "1");
      Add_Child (Pane, Button1);

      Button2 := Create_Child (Bar, "2");
      Add_Child (Pane, Button2);  --  Should split horizontally

      Button3 := Create_Child (Bar, "3");
      Add_Child (Pane, Button3);  --  Should split horizontally

      Button4 := Create_Child (Bar, "4");
      Split (Pane, Button2, Button4, Orientation_Vertical);

      Button := Create_Child (Bar, "5");
      Split (Pane, Button4, Button, Orientation_Horizontal);

      Show_All (Frame);
   end Run;

end Create_Splittable;