Code :
with Ada.Finalization; with Gtk.Main, Gtk.Widget, Gtk.Handlers, Gtk.Enums; use Gtk.Widget; with Gtk.Window, Gtk.Frame, Gtk.Box, Gtk.Menu_Bar, Gtk.Scrolled_Window; with Gtk.Button, Gtk.Combo_Box, Gtk.Spin_Button, Gtk.Notebook; use Gtk.Window, Gtk.Frame, Gtk.Box, Gtk.Menu_Bar, Gtk.Scrolled_Window; use Gtk.Button, Gtk.Combo_Box, Gtk.Spin_Button, Gtk.Notebook; with Gtk.Label,Gtk.Menu, Gtk.Menu_Item, Gtk.Stock, Gtk.Dialog; use Gtk.Label, Gtk.Menu, Gtk.Menu_Item, Gtk.Stock, Gtk.Dialog; with Gtk.Gentry; use Gtk.Gentry; package body Mutan.X is type T_Main_Window is new Ada.Finalization.Controlled with record Window : Gtk_Window; Frame : Gtk_Frame; Vbox : Gtk_Vbox; Menu_Bar : Gtk_Menu_Bar; Scroll : Gtk_Scrolled_Window; Tools : Gtk_Hbox; Start : Gtk_Button; Stop : Gtk_Button; Tempo : Gtk_Spin_Button; LTempo : Gtk_Label; Orchester : Gtk_Notebook; -- insert your instrument here. -- menu -- File_Menu : Gtk_Menu; File_Item : Gtk_Menu_Item; Quit_Item : Gtk_Menu_Item; Instrument_Menu : Gtk_Menu; Instrument_Item : Gtk_Menu_Item; New_Instrument_Item : Gtk_Menu_Item; end record; package Main_Handlers is new Gtk.Handlers.User_Callback(Gtk_Widget_Record, T_Main_Window); procedure Main_Quit(Widget : access Gtk.Widget.Gtk_Widget_Record'class; Main_Window : T_Main_Window); procedure Create_New_Instrument(Widget : access Gtk.Widget.Gtk_Widget_Record'class; Main_Window : T_Main_Window); procedure Initialize(Main_Window : in out T_Main_Window) is begin Gtk_New(Main_Window.window); Gtk_New(Main_Window.Frame); Gtk_New_Vbox(Main_Window.Vbox); Gtk_New(Main_Window.Menu_bar); Gtk_New(Main_Window.Scroll); Gtk_New_Hbox(Main_Window.Tools); Gtk_New_From_stock(Main_Window.Start, Stock_Media_play); Gtk_New_From_stock(Main_Window.Stop, Stock_Media_stop); Gtk_New(Main_Window.Tempo, 20.0, 300.0, 0.1); Gtk_New(Main_Window.LTempo, "Tempo :" ); Gtk_New(Main_Window.Orchester); Pack_Start(Main_Window.Tools, Main_Window.start, False, False, 0); Pack_Start(Main_Window.Tools, Main_Window.stop, False, False, 0); Pack_Start(Main_Window.Tools, Main_Window.Ltempo, False, False, 0); Pack_Start(Main_Window.Tools, Main_Window.tempo, False, False, 10); Add_With_Viewport(Main_Window.Scroll, Main_Window.Orchester); Pack_Start(Main_Window.Vbox, Main_Window.Menu_Bar, False, False, 0); Pack_Start(Main_Window.Vbox, Main_Window.tools, False, False, 0); Pack_Start(Main_Window.Vbox, Main_Window.Scroll, True, True, 0); Add(Main_Window.Frame, Main_Window.Vbox); Add(Main_Window.Window, Main_Window.Frame); -- menu -- Gtk_New(Main_Window.File_Menu); Gtk_New(Main_Window.File_Item, "File" ); Gtk_New(Main_Window.Quit_Item, "Quit..." ); Gtk_New(Main_Window.Instrument_Menu); Gtk_New(Main_Window.Instrument_Item, "Instruments" ); Gtk_New(Main_Window.New_Instrument_Item, "Create new instrument..." ); Append(Main_Window.File_Menu, Main_Window.Quit_Item); Append(Main_Window.Menu_Bar, Main_Window.File_Item); Set_Submenu(Main_Window.File_Item, Main_Window.File_menu); Append(Main_Window.Instrument_Menu, Main_Window.New_instrument_Item); Append(Main_Window.Menu_Bar, Main_Window.Instrument_Item); Set_Submenu(Main_Window.Instrument_Item, Main_Window.Instrument_menu); -- connecting -- Main_Handlers.Connect(Main_Window.Window, "destroy", Main_handlers.To_Marshaller(Main_Quit'access), Main_Window); Main_Handlers.Connect(Main_Window.Quit_item, "activate", Main_handlers.To_Marshaller(Main_Quit'access), Main_Window); Main_Handlers.Connect(Main_Window.New_Instrument_Item, "activate", Main_handlers.To_Marshaller(Create_New_instrument'access), Main_Window); Show_All(Main_Window.Window); end Initialize; procedure Main_Quit(Widget : access Gtk.Widget.Gtk_Widget_Record'class; Main_Window : T_Main_Window) is Dialog : Gtk_Dialog; Yes : Gtk_Widget; No : Gtk_Widget; Help : Gtk_Widget; begin loop Gtk_New(Dialog, "Quit ?", Main_Window.Window, modal); Yes := Add_Button(Dialog, "Yes", Gtk_Response_Yes); No := Add_Button(Dialog, "No", Gtk_Response_No); Help := Add_Button(Dialog, "Help", Gtk_Response_Help); case Run(Dialog) is when Gtk_Response_Yes => Gtk.Main.Main_Quit; exit; when Gtk_Response_No => exit; when Gtk_Response_Help => null; when others => null; end case; Destroy(Dialog); end loop; Destroy(Dialog); end Main_Quit; procedure Add_Frame (Widget : access Gtk.Widget.Gtk_Widget_Record'class; Main_Window : T_Main_Window); procedure Create_New_Instrument(Widget : access Gtk.Widget.Gtk_Widget_Record'class; Main_Window : T_Main_Window) is -- getting label of new instrument Window : Gtk_Window; Vbox : Gtk_Vbox; Label : Gtk_Label; Input : Gtk_Entry; Hbox : Gtk_Hbox; Ok : Gtk_Button; Cancel : Gtk_Button; Help : Gtk_Button; begin Gtk_New(Window); Gtk_New_Vbox(Vbox); Gtk_New(Label, "Enter name : " ); Gtk_New(Input); Gtk_New_Hbox(Hbox); Gtk_New_From_Stock(Ok, Stock_Ok); Gtk_New_From_Stock(Cancel, Stock_Cancel); Gtk_New_From_stock(Help, Stock_Help); Pack_Start(Vbox, Label, False, False, 0); Pack_Start(Vbox, Input, False, False, 0); Pack_Start(Hbox, Help, True, False, 0); Pack_Start(Hbox, Ok, True, False, 0); Pack_Start(Hbox, Cancel, True, False, 0); Pack_Start(Vbox, Hbox, False, False, 0); Add(Window, vbox); Show_All(Window); Main_Handlers.Connect(Ok, "clicked", Main_handlers.To_Marshaller(Add_Frame'access), Main_Window); Destroy(Window); end Create_New_Instrument; procedure Add_Frame (Widget : access Gtk.Widget.Gtk_Widget_Record'class; Main_Window : T_Main_Window) is begin Append_Page_menu(Main_Window.orchester, Main_Frame, label, label); end Add_Frame; procedure Xmain is begin Gtk.Main.Init; declare Main_Window : T_Main_Window; begin Gtk.Main.Main; end; end Xmain; end Mutan.X;
|