File: create_status.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 (222 lines) | stat: -rw-r--r-- 8,484 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
-----------------------------------------------------------------------
--          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.Handlers;   use Gtk.Handlers;
with Gtk.Status_Bar; use Gtk.Status_Bar;
with Gtk;            use Gtk;

with Ada.Text_IO;
with Interfaces.C.Strings;

package body Create_Status is

   package Status_Cb is new Handlers.Callback (Gtk_Status_Bar_Record);

   Counter : Gint := 1;

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

   function Help return String is
   begin
      return "A @bGtk_Status_Bar@B is generally found at the bottom of"
        & " application windows. It displays some help text, generally"
        & " depending on the current context in the application."
        & ASCII.LF
        & "In GtkAda, @bGtk_Status_Bar@B are organized as stacks: you push"
        & " some text onto the stack, and the top of the stack is always"
        & " displayed. You can then pop part of the stak to display the older"
        & " content of the @bGtk_Status_Bar@B. This behavior is especially"
        & " for temporarily displaying help in the status bar, but still being"
        & " able to show some other informations.";
   end Help;

   ----------
   -- Push --
   ----------

   procedure Push (Status : access Gtk_Status_Bar_Record'Class) is
      Id : Message_Id;
      pragma Unreferenced (Id);
   begin
      Id := Push (Status, 1, "Something" & Gint'Image (Counter));
      Counter := Counter + 1;
   end Push;

   ---------
   -- Pop --
   ---------

   procedure Pop (Status : access Gtk_Status_Bar_Record'Class) is
   begin
      Pop (Status, 1);
   end Pop;

   ------------
   -- Popped --
   ------------

   procedure Popped (Status : access Gtk_Status_Bar_Record'Class) is
      use type Messages_List.GSlist;
   begin
      if Get_Messages (Status) = Messages_List.Null_List then
         Counter := 1;
      end if;
   end Popped;

   -----------
   -- Steal --
   -----------

   procedure Steal (Status : access Gtk_Status_Bar_Record'Class) is
   begin
      Remove (Status, 1, 4);
   end Steal;

   --------------
   -- Contexts --
   --------------

   procedure Contexts (Status : access Gtk_Status_Bar_Record'Class) is
   begin
      Ada.Text_IO.Put_Line ("Status_Bar : Context : "
                            & "any context"
                            & "  Id="
                            & Context_Id'Image (Get_Context_Id
                                          (Status, "any context")));
      Ada.Text_IO.Put_Line ("Status_Bar : Context : "
                            & "idle messages"
                            & "  Id="
                            & Context_Id'Image (Get_Context_Id
                                          (Status, "idle message")));
      Ada.Text_IO.Put_Line ("Status_Bar : Context : "
                            & "some text"
                            & "  Id="
                            & Context_Id'Image (Get_Context_Id
                                          (Status, "some text")));
      Ada.Text_IO.Put_Line ("Status_Bar : Context : "
                            & "hit the mouse"
                            & "  Id="
                            & Context_Id'Image (Get_Context_Id
                                          (Status, "hit the mouse")));
      Ada.Text_IO.Put_Line ("Status_Bar : Context : "
                            & "hit the mouse2"
                            & "  Id="
                            & Context_Id'Image (Get_Context_Id
                                          (Status, "hit the mouse2")));
   end Contexts;

   ----------
   -- Dump --
   ----------

   procedure Dump (Status : access Gtk_Status_Bar_Record'Class) is
      List : Messages_List.GSlist := Get_Messages (Status);
      use type Messages_List.GSlist;
   begin
      while List /= Messages_List.Null_List loop
         declare
            Msg : constant Status_Bar_Msg := Messages_List.Get_Data (List);
         begin
            Ada.Text_IO.Put_Line ("Context Id = "
                                  & Context_Id'Image (Msg.Context)
                                  & " Message_Id = "
                                  & Message_Id'Image (Msg.Message)
                                  & " Text = "
                                  & Interfaces.C.Strings.Value (Msg.Text));
         end;
         List := Messages_List.Next (List);
      end loop;
   end Dump;

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

   procedure Run (Frame : access Gtk.Frame.Gtk_Frame_Record'Class) is
      Box1,
        Box2    : Gtk_Box;
      Status    : Gtk_Status_Bar;
      Button    : Gtk_Button;

   begin
      Set_Label (Frame, "Status Bar");

      Gtk_New_Vbox (Box1, False, 0);
      Add (Frame, Box1);

      Gtk_New_Vbox (Box2, False, 10);
      Set_Border_Width (Box2, 10);
      Pack_Start (Box1, Box2, False, False, 0);

      Gtk_New (Status);
      Pack_End (Box1, Status, False, False, 0);
      Status_Cb.Object_Connect (Status, "text_popped",
                                Status_Cb.To_Marshaller (Popped'Access),
                                Slot_Object => Status);

      Gtk_New (Button, "Push Something");
      Pack_Start (Box2, Button, False, False, 0);
      Status_Cb.Object_Connect (Button, "clicked",
                                Status_Cb.To_Marshaller (Push'Access),
                                Slot_Object => Status);

      Gtk_New (Button, "Pop");
      Pack_Start (Box2, Button, False, False, 0);
      Status_Cb.Object_Connect (Button, "clicked",
                                Status_Cb.To_Marshaller (Pop'Access),
                                Slot_Object => Status);

      Gtk_New (Button, "Steal Message_Id #4");
      Pack_Start (Box2, Button, False, False, 0);
      Status_Cb.Object_Connect (Button, "clicked",
                                Status_Cb.To_Marshaller (Steal'Access),
                                Slot_Object => Status);

      Gtk_New (Button, "Dump stack");
      Pack_Start (Box2, Button, False, False, 0);
      Status_Cb.Object_Connect (Button, "clicked",
                                Status_Cb.To_Marshaller (Dump'Access),
                                Slot_Object => Status);

      Gtk_New (Button, "Test contexts");
      Pack_Start (Box2, Button, False, False, 0);
      Status_Cb.Object_Connect (Button, "clicked",
                                Status_Cb.To_Marshaller (Contexts'Access),
                                Slot_Object => Status);

      Show_All (Frame);
   end Run;

end Create_Status;