File: create_box.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 (162 lines) | stat: -rw-r--r-- 6,738 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
-----------------------------------------------------------------------
--          GtkAda - Ada95 binding for the Gimp Toolkit              --
--                                                                   --
--                     Copyright (C) 1998-1999                       --
--        Emmanuel Briot, Joel Brobecker and Arnaud Charlet          --
--                                                                   --
-- 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 Glib; use Glib;
with Gtk.Box; use Gtk.Box;
with Gtk.Button; use Gtk.Button;
with Gtk.Frame; use Gtk.Frame;
with Gtk.Label; use Gtk.Label;
with Gtk.Separator; use Gtk.Separator;
with Gtk; use Gtk;

package body Create_Box is

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

   function Help return String is
   begin
      return "This demo show how you can efficiently use the @bGtk_Box@B " &
        "container." &
        ASCII.LF &
        ASCII.LF &
        "The upper half shows the different " &
        "combinations of the parameters @bHomogeneous@B, @bExpand@B and " &
        "@bFill@B. Note that for homogeneous boxes, @bExpand@B is irrelevant."
        & ASCII.LF &
        " - @bHomogeneous@B: If True all the widgets in the box will have the "
        & "same size as the largest child."
        & ASCII.LF &
        " - @bExpand@B: If True, the widget size will be bigger than the "
        & "minimum requested if more space is available. Its exact size "
        & "depends on the @bFill@B parameter"
        & ASCII.LF &
        " - @bFill@B: If False, the widget will be surrounded by empty space,"
        & " but its real size will be the minimum it requested."
        & ASCII.LF
        & ASCII.LF &
        "The second part of the demo shows the difference between "
        & "@bPack_Start@B and @bPack_End@B. The two resulting groups are "
        & "separated by a space that expands when the box is resized. This "
        & "space of course exists only when the widgets do not expand. "
        & "The buttons are inserted in the order specified (first button, "
        & " second button, ...)";
   end Help;

   -----------------
   -- Add_Buttons --
   -----------------

   procedure Add_Buttons (Vbox        : Gtk_Box;
                          Message     : String;
                          Homogeneous : Boolean;
                          Expand      : Boolean := False;
                          Fill        : Boolean := False)
   is
      Button : Gtk_Button;
      Box    : Gtk_Box;
      Label  : Gtk_Label;

   begin
      Gtk_New (Label, Message);
      Pack_Start (Vbox, Label, Expand => False, Fill => False);

      Gtk_New_Hbox (Box, Homogeneous => Homogeneous);
      Pack_Start (Vbox, Box, Expand => False, Fill => False);

      Gtk_New (Button, "Small");
      Pack_Start (Box, Button, Expand => Expand, Fill => Fill);

      Gtk_New (Button, "A bit longer");
      Pack_Start (Box, Button, Expand => Expand, Fill => Fill);

      Gtk_New (Button, "The longest button");
      Pack_Start (Box, Button, Expand => Expand, Fill => Fill);

   end Add_Buttons;

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

   procedure Run (Frame : access Gtk.Frame.Gtk_Frame_Record'Class) is
      Vbox    : Gtk_Box;
      Box     : Gtk_Box;
      Button  : Gtk_Button;
      Sep     : Gtk_Separator;

   begin
      Gtk.Frame.Set_Label (Frame, "Boxes");

      Gtk_New_Vbox (Vbox, Homogeneous => False, Spacing => 25);
      Add (Frame, Vbox);

      Gtk_New_Vbox (Box, Homogeneous => True);
      Pack_Start (Vbox, Box, Expand => False, Fill => False);
      Add_Buttons (Box, "Homogeneous => False, Expand => False",
                   Homogeneous => False, Expand => False, Fill => False);
      Add_Buttons (Box, "Homogeneous => False, Expand => True, Fill => False",
                   Homogeneous => False, Expand => True, Fill => False);
      Add_Buttons (Box, "Homogeneous => False, Expand => True, Fill => True",
                   Homogeneous => False, Expand => True, Fill => True);
      Add_Buttons (Box, "Homogeneous => True, Fill => False",
                   Homogeneous => True, Fill => False);
      Add_Buttons (Box, "Homogeneous => True, Fill => True",
                   Homogeneous => True, Fill => True);

      Gtk_New_Hseparator (Sep);
      Pack_Start (Vbox, Sep, Expand => False, Fill => True);

      Gtk_New_Vbox (Box, Homogeneous => False);
      Pack_Start (Vbox, Box, Expand => True, Fill => True, Padding => 10);

      Gtk_New (Button, "Pack_Start, First Button");
      Pack_Start (Box, Button, Expand => False, Fill => False);

      Gtk_New (Button, "Pack_Start, Second Button");
      Pack_Start (Box, Button, Expand => False, Fill => False);

      Gtk_New (Button, "Pack_Start, Third Button");
      Pack_Start (Box, Button, Expand => False, Fill => False);

      Gtk_New (Button, "Pack_End, First Button");
      Pack_End (Box, Button, Expand => False, Fill => False);

      Gtk_New (Button, "Pack_End, Second Button");
      Pack_End (Box, Button, Expand => False, Fill => False);

      Gtk_New (Button, "Pack_End, Third Button");
      Pack_End (Box, Button, Expand => False, Fill => False);


      Show_All (Frame);
   end Run;

end Create_Box;