~ubuntu-branches/ubuntu/jaunty/libgtkada2/jaunty

« back to all changes in this revision

Viewing changes to testgtk/create_notebook.adb

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2008-08-11 09:46:51 UTC
  • mfrom: (6.1.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20080811094651-9mjd6acwa98ffw5c
Tags: 2.12.0-2ubuntu1
Add lpia to supported architectures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
--          GtkAda - Ada95 binding for the Gimp Toolkit              --
3
3
--                                                                   --
4
4
--   Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet   --
 
5
--                  Copyright (C) 2001-2007 AdaCore                  --
5
6
--                                                                   --
6
7
-- This library is free software; you can redistribute it and/or     --
7
8
-- modify it under the terms of the GNU General Public               --
19
19
-- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      --
20
20
-- Boston, MA 02111-1307, USA.                                       --
21
21
--                                                                   --
22
22
-----------------------------------------------------------------------
23
23
 
24
24
with Gdk;
37
31
with Gtk.Box;             use Gtk.Box;
38
32
with Gtk.Button;          use Gtk.Button;
39
33
with Gtk.Check_Button;    use Gtk.Check_Button;
 
34
with Gtk.Combo_Box;       use Gtk.Combo_Box;
40
35
with Gtk.Enums;           use Gtk.Enums;
41
36
with Gtk.Handlers;        use Gtk.Handlers;
42
37
with Gtk.Image;           use Gtk.Image;
43
38
with Gtk.Label;           use Gtk.Label;
44
 
with Gtk.Menu;            use Gtk.Menu;
45
39
with Gtk.Notebook;        use Gtk.Notebook;
46
 
with Gtk.Option_Menu;     use Gtk.Option_Menu;
47
 
with Gtk.Radio_Menu_Item; use Gtk.Radio_Menu_Item;
48
40
with Gtk.Separator;       use Gtk.Separator;
49
41
with Gtk.Widget;          use Gtk.Widget;
50
42
with Gtk;                 use Gtk;
55
47
   package Note_Cb is new Handlers.Callback (Gtk_Notebook_Record);
56
48
   package Button_Cb is new Handlers.User_Callback
57
49
     (Gtk_Check_Button_Record, Gtk_Notebook);
 
50
   package Combo_Cb is new Handlers.User_Callback
 
51
     (Gtk_Combo_Box_Record, Gtk_Notebook);
58
52
   package Notebook_Cb is new Handlers.Callback (Gtk_Notebook_Record);
59
53
   package Frame_Cb is new Handlers.User_Callback
60
54
     (Gtk_Check_Button_Record, Gtk_Frame);
65
59
   Book_Closed_Mask : Gdk_Bitmap;
66
60
   Notebook         : Gtk_Notebook;
67
61
 
 
62
   procedure Tab_Fill
 
63
     (Button : access Gtk_Check_Button_Record'Class;
 
64
      Child  : in Gtk_Frame);
 
65
   --  Fill all the space with tabs
 
66
 
 
67
   procedure Tab_Expand
 
68
     (Button : access Gtk_Check_Button_Record'Class;
 
69
      Child  : in Gtk_Frame);
 
70
   --  Expand tabs
 
71
 
 
72
   procedure Hide (Widget : access Gtk_Widget_Record'Class);
 
73
   --  Hide tabs
 
74
 
 
75
   procedure Next_Page (Notebook : access Gtk_Notebook_Record'Class);
 
76
   --  Switch to the next page
 
77
 
 
78
   procedure Prev_Page (Notebook : access Gtk_Notebook_Record'Class);
 
79
   --  Switch to the previous page
 
80
 
 
81
   procedure Tab_Pack
 
82
     (Button : access Gtk_Check_Button_Record'Class;
 
83
      Child  : in Gtk_Frame);
 
84
 
 
85
   procedure Create_Pages
 
86
     (Notebook  : access Gtk_Notebook_Record'Class;
 
87
      The_Start : Gint;
 
88
      The_End   : Gint);
 
89
   --  Create the notebook pages
 
90
 
 
91
   procedure Rotate_Notebook (Notebook : access Gtk_Notebook_Record'Class);
 
92
   --  Rotate the tabs around the notebook
 
93
 
 
94
   procedure Show_All_Pages (Notebook : access Gtk_Notebook_Record'Class);
 
95
   --  Show all pages
 
96
 
 
97
   procedure Change_Tabs_Display
 
98
     (Combo    : access Gtk_Combo_Box_Record'Class;
 
99
      Notebook : Gtk_Notebook);
 
100
   --  Change notebook to be displayed without tabs, with scrollable tabs or
 
101
   --  with the standard tabs.
 
102
 
 
103
   procedure Notebook_Popup
 
104
     (Button   : access Gtk_Check_Button_Record'Class;
 
105
      Notebook : Gtk_Notebook);
 
106
   --  Allow popup window to switch from a page to another
 
107
 
 
108
   procedure Homogeneous
 
109
     (Button   : access Gtk_Check_Button_Record'Class;
 
110
      Notebook : Gtk_Notebook);
 
111
   --  Set tabs homogeneous
 
112
 
 
113
   procedure Set_Tabs_Detachable
 
114
     (Button   : access Gtk_Check_Button_Record'Class;
 
115
      Notebook : Gtk_Notebook);
 
116
   --  Set tabs detachable
 
117
 
 
118
   procedure Set_Tabs_Reorderable
 
119
     (Button   : access Gtk_Check_Button_Record'Class;
 
120
      Notebook : Gtk_Notebook);
 
121
   --  Set tabs reorderable
 
122
 
 
123
   procedure Page_Switch
 
124
     (Notebook : access Gtk_Notebook_Record'Class;
 
125
      Params   : Gtk.Arguments.Gtk_Args);
 
126
   --  Switch the current page
 
127
 
68
128
   ----------
69
129
   -- Help --
70
130
   ----------
82
142
   -- Tab_Fill --
83
143
   --------------
84
144
 
85
 
   procedure Tab_Fill (Button : access Gtk_Check_Button_Record'Class;
86
 
                       Child  : in Gtk_Frame) is
 
145
   procedure Tab_Fill
 
146
     (Button : access Gtk_Check_Button_Record'Class;
 
147
      Child  : in Gtk_Frame)
 
148
   is
87
149
      Expand, Fill : Boolean;
88
150
      Typ          : Gtk_Pack_Type;
89
151
   begin
96
158
   -- Tab_Expand --
97
159
   ----------------
98
160
 
99
 
   procedure Tab_Expand (Button : access Gtk_Check_Button_Record'Class;
100
 
                         Child  : in Gtk_Frame) is
 
161
   procedure Tab_Expand
 
162
     (Button : access Gtk_Check_Button_Record'Class;
 
163
      Child  : in Gtk_Frame)
 
164
   is
101
165
      Expand, Fill : Boolean;
102
166
      Typ          : Gtk_Pack_Type;
103
167
   begin
137
201
   -- Tab_Pack --
138
202
   --------------
139
203
 
140
 
   procedure Tab_Pack (Button : access Gtk_Check_Button_Record'Class;
141
 
                       Child  : in Gtk_Frame) is
 
204
   procedure Tab_Pack
 
205
     (Button : access Gtk_Check_Button_Record'Class;
 
206
      Child  : in Gtk_Frame)
 
207
   is
142
208
      Expand, Fill : Boolean;
143
209
      Typ          : Gtk_Pack_Type;
144
210
   begin
186
252
         Gtk_New (Check, "Fill tab");
187
253
         Pack_Start (Hbox, Check, True, True, 5);
188
254
         Set_Active (Check, True);
189
 
         Frame_Cb.Connect (Check, "toggled",
190
 
                           Frame_Cb.To_Marshaller (Tab_Fill'Access),
191
 
                           Child);
 
255
         Frame_Cb.Connect
 
256
           (Check, "toggled",
 
257
            Frame_Cb.To_Marshaller (Tab_Fill'Access),
 
258
            Child);
192
259
 
193
260
         Gtk_New (Check, "Expand tab");
194
261
         Pack_Start (Hbox, Check, True, True, 5);
195
262
         Set_Active (Check, True);
196
 
         Frame_Cb.Connect (Check, "toggled",
197
 
                           Frame_Cb.To_Marshaller (Tab_Expand'Access),
198
 
                           Child);
 
263
         Frame_Cb.Connect
 
264
           (Check, "toggled",
 
265
            Frame_Cb.To_Marshaller (Tab_Expand'Access),
 
266
            Child);
199
267
 
200
268
         Gtk_New (Check, "Pack end");
201
269
         Pack_Start (Hbox, Check, True, True, 5);
202
270
         Set_Active (Check, True);
203
 
         Frame_Cb.Connect (Check, "toggled",
204
 
                           Frame_Cb.To_Marshaller (Tab_Pack'Access),
205
 
                           Child);
 
271
         Frame_Cb.Connect
 
272
           (Check, "toggled",
 
273
            Frame_Cb.To_Marshaller (Tab_Pack'Access),
 
274
            Child);
206
275
 
207
276
         Gtk_New (Button, "Hide page");
208
277
         Pack_Start (Vbox, Button, True, True, 5);
240
309
 
241
310
   procedure Rotate_Notebook (Notebook : access Gtk_Notebook_Record'Class) is
242
311
   begin
243
 
      Set_Tab_Pos (Notebook,
244
 
                   Gtk_Position_Type'Val
245
 
                   ((Gtk_Position_Type'Pos (Get_Tab_Pos (Notebook)) + 1)
246
 
                    mod 4));
 
312
      Set_Tab_Pos
 
313
        (Notebook,
 
314
         Gtk_Position_Type'Val
 
315
           ((Gtk_Position_Type'Pos (Get_Tab_Pos (Notebook)) + 1)
 
316
            mod 4));
247
317
   end Rotate_Notebook;
248
318
 
249
319
   --------------------
255
325
      Show_All (Notebook);
256
326
   end Show_All_Pages;
257
327
 
258
 
   -----------------------
259
 
   -- Standard_Notebook --
260
 
   -----------------------
261
 
 
262
 
   procedure Standard_Notebook (Notebook : access Gtk_Notebook_Record'Class) is
263
 
   begin
264
 
      Set_Show_Tabs (Notebook, True);
265
 
      Set_Scrollable (Notebook, False);
266
 
      if Get_N_Pages (Notebook) = 15 then
267
 
         for I in 0 .. 9 loop
268
 
            Remove_Page (Notebook, 5);
269
 
         end loop;
270
 
      end if;
271
 
   end Standard_Notebook;
272
 
 
273
 
   ---------------------
274
 
   -- Notabs_Notebook --
275
 
   ---------------------
276
 
 
277
 
   procedure Notabs_Notebook (Notebook : access Gtk_Notebook_Record'Class) is
278
 
   begin
279
 
      Set_Show_Tabs (Notebook, False);
280
 
      if Get_N_Pages (Notebook) = 15 then
281
 
         for I in 0 .. 9 loop
282
 
            Remove_Page (Notebook, 5);
283
 
         end loop;
284
 
      end if;
285
 
   end Notabs_Notebook;
286
 
 
287
 
   -------------------------
288
 
   -- Scrollable_Notebook --
289
 
   -------------------------
290
 
 
291
 
   procedure Scrollable_Notebook (Notebook : access Gtk_Notebook_Record'Class)
 
328
   -------------------------
 
329
   -- Change_Tabs_Display --
 
330
   -------------------------
 
331
 
 
332
   procedure Change_Tabs_Display
 
333
     (Combo    : access Gtk_Combo_Box_Record'Class;
 
334
      Notebook : Gtk_Notebook)
292
335
   is
 
336
      Active_Text : constant String := Get_Active_Text (Combo);
293
337
   begin
294
 
      Set_Show_Tabs (Notebook, True);
295
 
      Set_Scrollable (Notebook, True);
296
 
      if Get_N_Pages (Notebook) = 5 then
297
 
         Create_Pages (Notebook, 6, 15);
 
338
      if Active_Text = "Standard" then
 
339
         Set_Show_Tabs (Notebook, True);
 
340
         Set_Scrollable (Notebook, False);
 
341
         if Get_N_Pages (Notebook) = 15 then
 
342
            for I in 0 .. 9 loop
 
343
               Remove_Page (Notebook, 5);
 
344
            end loop;
 
345
         end if;
 
346
      elsif Active_Text = "w/o tabs" then
 
347
         Set_Show_Tabs (Notebook, False);
 
348
         if Get_N_Pages (Notebook) = 15 then
 
349
            for I in 0 .. 9 loop
 
350
               Remove_Page (Notebook, 5);
 
351
            end loop;
 
352
         end if;
 
353
      elsif Active_Text = "Scrollable" then
 
354
         Set_Show_Tabs (Notebook, True);
 
355
         Set_Scrollable (Notebook, True);
 
356
         if Get_N_Pages (Notebook) = 5 then
 
357
            Create_Pages (Notebook, 6, 15);
 
358
         end if;
298
359
      end if;
299
 
   end Scrollable_Notebook;
 
360
   end Change_Tabs_Display;
300
361
 
301
362
   --------------------
302
363
   -- Notebook_Popup --
303
364
   --------------------
304
365
 
305
 
   procedure Notebook_Popup (Button : access Gtk_Check_Button_Record'Class;
306
 
                             Notebook : in Gtk_Notebook) is
 
366
   procedure Notebook_Popup
 
367
     (Button   : access Gtk_Check_Button_Record'Class;
 
368
      Notebook : Gtk_Notebook) is
307
369
   begin
308
370
      if Get_Active (Button) then
309
371
         Popup_Enable (Notebook);
316
378
   -- Homogeneous --
317
379
   -----------------
318
380
 
319
 
   procedure Homogeneous (Button : access Gtk_Check_Button_Record'Class;
320
 
                          Notebook : in Gtk_Notebook) is
 
381
   procedure Homogeneous
 
382
     (Button   : access Gtk_Check_Button_Record'Class;
 
383
      Notebook : Gtk_Notebook) is
321
384
   begin
322
385
      Set_Property
323
386
        (Notebook, Gtk.Notebook.Homogeneous_Property, Get_Active (Button));
324
387
   end Homogeneous;
325
388
 
 
389
   --------------------------
 
390
   -- Set_Pages_Detachable --
 
391
   --------------------------
 
392
 
 
393
   procedure Set_Tabs_Detachable
 
394
     (Button   : access Gtk_Check_Button_Record'Class;
 
395
      Notebook : Gtk_Notebook) is
 
396
   begin
 
397
      for N in 0 .. Get_N_Pages (Notebook) - 1 loop
 
398
         Set_Tab_Detachable
 
399
           (Notebook, Get_Nth_Page (Notebook, N), Get_Active (Button));
 
400
      end loop;
 
401
   end Set_Tabs_Detachable;
 
402
 
 
403
   ---------------------------
 
404
   -- Set_Pages_Reorderable --
 
405
   ---------------------------
 
406
 
 
407
   procedure Set_Tabs_Reorderable
 
408
     (Button   : access Gtk_Check_Button_Record'Class;
 
409
      Notebook : Gtk_Notebook) is
 
410
   begin
 
411
      for N in 0 .. Get_N_Pages (Notebook) - 1 loop
 
412
         Set_Tab_Reorderable
 
413
           (Notebook, Get_Nth_Page (Notebook, N), Get_Active (Button));
 
414
      end loop;
 
415
   end Set_Tabs_Reorderable;
 
416
 
326
417
   -----------------
327
418
   -- Page_Switch --
328
419
   -----------------
361
452
   ---------
362
453
 
363
454
   procedure Run (Frame : access Gtk.Frame.Gtk_Frame_Record'Class) is
364
 
      Box1            : Gtk_Box;
365
 
      Box2            : Gtk_Box;
366
 
      Option_Menu     : Gtk_Option_Menu;
367
 
      Menu            : Gtk_Menu;
368
 
      Menu_Item       : Gtk_Radio_Menu_Item;
369
 
      Group           : Widget_SList.GSlist;
370
 
      Button          : Gtk_Check_Button;
371
 
      Button2         : Gtk_Button;
372
 
      Label           : Gtk_Label;
373
 
      Separator       : Gtk_Separator;
 
455
      Box1      : Gtk_Box;
 
456
      Box2      : Gtk_Box;
 
457
      Combo     : Gtk_Combo_Box;
 
458
      Button    : Gtk_Check_Button;
 
459
      Button2   : Gtk_Button;
 
460
      Label     : Gtk_Label;
 
461
      Separator : Gtk_Separator;
374
462
 
375
463
   begin
376
464
      Set_Label (Frame, "Notebook");
379
467
      Add (Frame, Box1);
380
468
 
381
469
      Gtk_New (Notebook);
 
470
 
382
471
      Notebook_Cb.Connect
383
472
        (Notebook, "switch_page", Page_Switch'Access);
384
473
      Set_Tab_Pos (Notebook, Pos_Top);
386
475
      Set_Border_Width (Notebook, 10);
387
476
      Realize (Notebook);
388
477
 
389
 
      Create_From_Xpm_D (Book_Open,
390
 
                         Get_Window (Notebook),
391
 
                         Book_Open_Mask, Null_Color,
392
 
                         Book_Open_Xpm);
393
 
      Create_From_Xpm_D (Book_Closed,
394
 
                         Get_Window (Notebook),
395
 
                         Book_Closed_Mask, Null_Color,
396
 
                         Book_Closed_Xpm);
 
478
      Create_From_Xpm_D
 
479
        (Book_Open,
 
480
         Get_Window (Notebook),
 
481
         Book_Open_Mask, Null_Color,
 
482
         Book_Open_Xpm);
 
483
      Create_From_Xpm_D
 
484
        (Book_Closed,
 
485
         Get_Window (Notebook),
 
486
         Book_Closed_Mask, Null_Color,
 
487
         Book_Closed_Xpm);
397
488
 
398
489
      Create_Pages (Notebook, 1, 5);
399
490
 
415
506
        (Button, "clicked",
416
507
         Button_Cb.To_Marshaller (Homogeneous'Access), Notebook);
417
508
 
 
509
      Gtk_New (Button, "reorderable tabs");
 
510
      Pack_Start (Box2, Button, True, False, 0);
 
511
      Button_Cb.Connect
 
512
        (Button, "clicked",
 
513
         Button_Cb.To_Marshaller (Set_Tabs_Reorderable'Access), Notebook);
 
514
 
 
515
      Gtk_New (Button, "detachable tabs");
 
516
      Pack_Start (Box2, Button, True, False, 0);
 
517
      Button_Cb.Connect
 
518
        (Button, "clicked",
 
519
         Button_Cb.To_Marshaller (Set_Tabs_Detachable'Access), Notebook);
 
520
 
418
521
      Gtk_New_Hbox (Box2, False, 5);
419
522
      Set_Border_Width (Box2, 10);
420
523
      Pack_Start (Box1, Box2, False, True, 0);
422
525
      Gtk_New (Label, "Notebook Style :");
423
526
      Pack_Start (Box2, Label, False, True, 0);
424
527
 
425
 
      Gtk_New (Option_Menu);
426
 
      Gtk_New (Menu);
427
 
 
428
 
      Gtk_New (Menu_Item, Group, "Standard");
429
 
      Note_Cb.Object_Connect
430
 
        (Menu_Item, "activate",
431
 
         Note_Cb.To_Marshaller (Standard_Notebook'Access),
432
 
         Slot_Object => Notebook);
433
 
      Group := Gtk.Radio_Menu_Item.Get_Group (Menu_Item);
434
 
      Append (Menu, Menu_Item);
435
 
      Show (Menu_Item);
436
 
 
437
 
      Gtk_New (Menu_Item, Group, "w/o Tabs");
438
 
      Note_Cb.Object_Connect
439
 
        (Menu_Item, "activate",
440
 
         Note_Cb.To_Marshaller (Notabs_Notebook'Access),
441
 
         Slot_Object => Notebook);
442
 
      Group := Gtk.Radio_Menu_Item.Get_Group (Menu_Item);
443
 
      Append (Menu, Menu_Item);
444
 
      Show (Menu_Item);
445
 
 
446
 
      Gtk_New (Menu_Item, Group, "Scrollable");
447
 
      Note_Cb.Object_Connect
448
 
        (Menu_Item, "activate",
449
 
         Note_Cb.To_Marshaller (Scrollable_Notebook'Access),
450
 
         Slot_Object => Notebook);
451
 
      Group := Gtk.Radio_Menu_Item.Get_Group (Menu_Item);
452
 
      Append (Menu, Menu_Item);
453
 
      Show (Menu_Item);
454
 
 
455
 
      Set_Menu (Option_Menu, Menu);
456
 
      Pack_Start (Box2, Option_Menu, False, False, 0);
 
528
      Gtk_New_Text (Combo);
 
529
      Append_Text (Combo, "Standard");
 
530
      Append_Text (Combo, "w/o tabs");
 
531
      Append_Text (Combo, "Scrollable");
 
532
      Combo_Cb.Connect
 
533
        (Combo, "changed",
 
534
         Combo_Cb.To_Marshaller (Change_Tabs_Display'Access), Notebook);
 
535
      Pack_Start (Box2, Combo, False, False, 0);
457
536
 
458
537
      Gtk_New (Button2, "Show all pages");
459
538
      Pack_Start (Box2, Button2, False, True, 0);