File: packbox_test.adb

package info (click to toggle)
libgtkada 2.24.4dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 12,208 kB
  • ctags: 1,676
  • sloc: ada: 119,686; ansic: 4,719; sh: 3,003; makefile: 690; xml: 338; perl: 70
file content (287 lines) | stat: -rw-r--r-- 8,878 bytes parent folder | download | duplicates (6)
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Text_IO; use Ada.Text_IO;
with Gtk.Main;
with Gtk.Window, Gtk.Button, Gtk.Box, Gtk.Separator, Gtk.Label, Gtk.Box;
use  Gtk.Window, Gtk.Button, Gtk.Box, Gtk.Separator, Gtk.Label, Gtk.Box;
with Packbox; use Packbox;

procedure Packbox_Test is
   Window     : Gtk_Window;
   Button     : Gtk_Button;
   Box1, Box2 : Gtk_Box;
   Separator  : Gtk_Separator;
   Label      : Gtk_Label;
   Quit_Box   : Gtk_Box;
   Which      : Integer;

begin
   Gtk.Main.Init;

   if Argument_Count /= 1 then
      Put_Line ("usage: packbox_test num, where num is 1, 2, or 3.");
      --  This just does cleanup in GtkAda and exits with an exit status of 1.
      Gtk.Main.Gtk_Exit (1);
   end if;

   Which := Integer'Value (Argument (1));

   --  Create our window

   Gtk_New (Window);

   --  You should always remember to connect the delete_event signal
   --  to the main window. This is very important for proper intuitive
   --  behavior.

   Return_Handlers.Connect
     (Window, "delete_event",
      Return_Handlers.To_Marshaller (Delete_Event'Access));
   Set_Border_Width (Window, 10);

   --  We create a vertical box (Vbox) to pack the horizontal boxes into.
   --  This allows us to stack the horizontal boxes filled with buttons one
   --  on top of the other in this vbox.

   Gtk_New_Vbox (Box => Box1, Homogeneous => False, Spacing => 0);

   --  Which example to show. These correspond to the pictures above.

   case Which is
      when 1 =>
         --  create a new label.

         Gtk_New (Label, "Gtk_New_Hbox (Homogeneous => False, Spacing => 0);");

         --  Align the label to the left side.  We'll discuss this function and
         --  others in the section on Widget Attributes.

         Set_Alignment (Label, 0.0, 0.0);

         --  Pack the label into the vertical box (vbox box1).  Remember that
         -- widgets added to a vbox will be packed one on top of the other in
         -- order.

         Pack_Start
           (In_Box  => Box1,
            Child   => Label,
            Expand  => False,
            Fill    => False,
            Padding => 0);

        --  Call our make box function

        Box2 := Make_Box
          (Homogeneous => False,
           Spacing     => 0,
           Expand      => False,
           Fill        => False,
           Padding     => 0);

        Pack_Start
          (In_Box  => Box1,
           Child   => Box2,
           Expand  => False,
           Fill    => False,
           Padding => 0);

        --  Call our make box function

        Box2 := Make_Box
          (Homogeneous => False,
           Spacing     => 0,
           Expand      => True,
           Fill        => False,
           Padding     => 0);

        Pack_Start
          (In_Box  => Box1,
           Child   => Box2,
           Expand  => False,
           Fill    => False,
           Padding => 0);

        Box2 := Make_Box
          (Homogeneous => False,
           Spacing     => 0,
           Expand      => True,
           Fill        => True,
           Padding     => 0);

        Pack_Start
          (In_Box  => Box1,
           Child   => Box2,
           Expand  => False,
           Fill    => False,
           Padding => 0);

        --  Creates a separator, we'll learn more about these later,
        --  but they are quite simple.

        Gtk_New_Hseparator (Separator);

        --  Pack the separator into the vbox. Remember each of these
        --  widgets is being packed into a vbox, so they'll be stacked
        --  vertically.

        Pack_Start
          (In_Box  => Box1,
           Child   => Separator,
           Expand  => False,
           Fill    => True,
           Padding => 5);

        --  Create another new label.

        Gtk_New (Label, "Gtk_New_Hbox (Homogeneous => True, Spacing => 0);");
        Set_Alignment (Label, 0.0, 0.0);
        Pack_Start (Box1, Label, Expand => False, Fill => False, Padding => 0);

        Box2 := Make_Box (True, 0, True, False, 0);
        Pack_Start (Box1, Box2, Expand => False, Fill => False, Padding => 0);

        Box2 := Make_Box (True, 0, True, True, 0);
        Pack_Start (Box1, Box2, Expand => False, Fill => False, Padding => 0);

        --  Another new separator.
        Gtk_New_Hseparator (Separator);

        Pack_Start (Box1, Separator,
          Expand => False, Fill => True, Padding => 5);

      when 2 =>
         --  Create a new label, remember Box1 is a Vbox as created
         --  near the beginning of Packbox_Test

         Gtk_New (Label,
           "Gtk_New_Hbox (Homogeneous => False, Spacing => 10);");
         Set_Alignment (Label, 0.0, 0.0);
         Pack_Start
           (Box1, Label, Expand => False, Fill => False, Padding => 0);

         Box2 := Make_Box
           (Homogeneous => False,
            Spacing     => 10,
            Expand      => True,
            Fill        => False,
            Padding     => 0);
         Pack_Start (Box1, Box2, Expand => False, Fill => False, Padding => 0);

         Box2 := Make_Box
           (Homogeneous => False,
            Spacing     => 10,
            Expand      => True,
            Fill        => True,
            Padding     => 0);
         Pack_Start (Box1, Box2, Expand => False, Fill => False, Padding => 0);

         Gtk_New_Hseparator (Separator);
         Pack_Start
           (Box1, Separator,
            Expand => False, Fill => True, Padding => 5);

         Gtk_New (Label, "Gtk_New_Hbox (Homogeneous => False, Spacing => 0);");
         Set_Alignment (Label, 0.0, 0.0);
         Pack_Start
           (Box1, Label, Expand => False, Fill => False, Padding => 0);

         Box2 := Make_Box
           (Homogeneous => False,
            Spacing     => 0,
            Expand      => True,
            Fill        => False,
            Padding     => 10);
         Pack_Start (Box1, Box2, Expand => False, Fill => False, Padding => 0);

         Box2 := Make_Box
           (Homogeneous => False,
            Spacing     => 0,
            Expand      => True,
            Fill        => True,
            Padding     => 10);
         Pack_Start (Box1, Box2, Expand => False, Fill => False, Padding => 0);

         Gtk_New_Hseparator (Separator);

         Pack_Start
           (Box1, Separator, Expand => False, Fill => True, Padding => 5);

      when 3 =>
         --  This demonstrates the ability to use Pack_End to
         --  right justify widgets. First, we create a new box as before.

         Box2 := Make_Box
           (Homogeneous => False,
            Spacing     => 0,
            Expand      => False,
            Fill        => False,
            Padding     => 0);

         --  Create the label that will be put at the end.

         Gtk_New (Label, "end");

         --  Pack it using Pack_End, so it is put on the right
         --  side of the Hbox created in the Make_Box() call.

         Pack_End (Box2, Label, Expand => False, Fill => False, Padding => 0);

         --  Pack Box2 into Box1 (the Vbox remember ? :)

         Pack_Start (Box1, Box2, Expand => False, Fill => False, Padding => 0);

         --  A separator for the bottom.

         Gtk_New_Hseparator (Separator);

         --  This explicitly sets the separator to 400 pixels wide by 5 pixels
         --  high. This is so the hbox we created will also be 400 pixels wide,
         --  and the "end" label will be separated from the other labels in the
         --  hbox. Otherwise, all the widgets in the hbox would be packed as
         --  close together as possible.

         Set_Usize (Separator, 400, 5);

         --  pack the separator into the Vbox (Box1) created near the start
         --  of Packbox_Test

         Pack_Start
           (Box1, Separator, Expand => False, Fill => True, Padding => 5);

      when others =>
         raise Program_Error;
   end case;

   --  Create another new Hbox.. remember we can use as many as we need!
   Gtk_New_Hbox (Quit_Box, Homogeneous => False, Spacing => 0);

   --  Our quit button.
   Gtk_New (Button, "Quit");

   --  Setup the signal to terminate the program when the button is clicked
   Handlers.Object_Connect
     (Button, "clicked",
      Handlers.To_Marshaller (Quit'Access),
      Window);

   --  Pack the button into the quitbox.

   Pack_Start (Quit_Box, Button, Expand => True, Fill => False, Padding => 0);

   --  pack the quit box into the Vbox (Box1)
   Pack_Start (Box1, Quit_Box, False, False, 0);

   --  Pack the Vbox (Box1) which now contains all our widgets, into the
   --  main window.
   Add (Window, Box1);

   --  Show the window and all its children at once
   Show_All (Window);

   --  And of course, our main function.
   Gtk.Main.Main;

   --  Control returns here when Gtk.Main.Main_Quit is called, but not when
   --  Gtk_Exit is used.

   Put_Line ("Exiting of Packbox_Test");
end Packbox_Test;