----------------------------
-- with & use clause --
----------------------------
...
...
...
package body Main_Windows is
package Notebook_Cb is new Gtk.Handlers.User_Callback
(Gtk_Notebook_Record, Gtk_Notebook);
package Window_Cb is new Handlers.Callback (Gtk_Widget_Record);
package Return_Window_Cb is new Handlers.Return_Callback
(Gtk_Widget_Record, Boolean);
procedure Exit_Main (Object : access Gtk_Widget_Record'Class);
-- Callbacks when the main window is killed
function Delete_Event
(Object : access Gtk_Widget_Record'Class) return Boolean;
-----------------
-- Exit_Main --
-----------------
procedure Exit_Main (Object : access Gtk_Widget_Record'Class) is
pragma Unreferenced (Object);
begin
Gtk.Main.Main_Quit;
end Exit_Main;
------------------
-- Delete_Event --
------------------
function Delete_Event
(Object : access Gtk_Widget_Record'Class) return Boolean
is
pragma Unreferenced (Object);
begin
-- Do not allow the user to kill the window by clicking on the icon,
-- he has to press explicitly "Quit"
return True;
end Delete_Event;
-------------
-- Gtk_New --
-------------
procedure Gtk_New (Win : out Main_Window) is
begin
Win := new Main_Window_Record;
Initialize (Win);
end Gtk_New;
----------------
-- Initialize --
----------------
procedure Initialize (Win : access Main_Window_Record'Class) is
Frame : Gtk.Frame.Gtk_Frame;
Label : Gtk.Label.Gtk_Label;
Vbox : Gtk.Box.Gtk_Box;
Style : Gtk_Style;
Button : Gtk.Button.Gtk_Button;
Bbox : Gtk.Hbutton_Box.Gtk_Hbutton_Box;
begin
Gtk.Window.Initialize (Win, Gtk.Enums.Window_Toplevel);
Window_Cb.Connect (Win, "destroy",
Window_Cb.To_Marshaller (Exit_Main'Access));
Return_Window_Cb.Connect
(Win, "delete_event",
Return_Window_Cb.To_Marshaller (Delete_Event'Access));
-- The global box
Gtk_New_Vbox (Vbox, Homogeneous => False, Spacing => 0);
Add (Win, Vbox);
-- Label
Style := Copy (Get_Style (Win));
Set_Font_Description (Style, From_String ("Helvetica Bold 18" ));
Gtk_New (Label, "xbusiness" );
Set_Style (Label, Style);
Pack_Start (Vbox, Label, Expand => False, Fill => False, Padding => 10);
-- Notebook creation
Gtk_New (Win.Notebook);
Pack_Start (Vbox, Win.Notebook, Expand => True, Fill => True);
Gtk_New (Bbox);
Set_Layout (Bbox, Buttonbox_Spread);
Set_Spacing (Bbox, 40);
Gtk_New (Button, "Quit" );
Pack_Start (Bbox, Button, Expand => True, Fill => False);
Window_Cb.Connect (Button, "clicked",
Window_Cb.To_Marshaller (Exit_Main'Access));
Pack_End (Vbox, Bbox, Expand => False, Padding => 5);
-- Display everything
Show_All (Vbox);
end Initialize;
end Main_Windows;