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
| --***************************************************************
-- Nom du programme : Calculatrice
-- Type : Interface
-- Sujet : Calculatrice construite à partir de GTKADA
--
-- Auteur : Pascal RICHARD
-- Version : 1.0
-- Création : 08/03/2007
-- Dernière modif. : 10/03/2007
--
-- Outils : AIDE - GPS - MSys
-- Remarques : Environnement Windows XP SP2
--****************************************************************
with Glib; use Glib;
with Gtk.Main; use Gtk.Main;
with Gtk.Window; use Gtk.Window;
with Gtk.Frame; use Gtk.Frame;
with Gtk.GEntry; use Gtk.GEntry;
with Gtk.Enums; use Gtk.Enums;
with Gtk.Button; use Gtk.Button;
with Gtk.Check_Button; use Gtk.Check_Button;
with Gtk.Table; use Gtk.Table;
with Gtk.Handlers; use Gtk.Handlers;
with gtk.widget; use gtk.widget;
procedure cessai is
Table : gtk_table;
Fenetre : gtk_window;
Ecran, Affich_result : Gtk_GEntry;
Frame_affich, Frame_ope, Frame_nomb : gtk_frame;
btn_plus : Gtk_Button;
btn_clear : Gtk_Button;
--bouton0, bouton1 : gtk_button;
pos : Gint := -1;
a : string := "";
bouton: array(0 .. 1) of Gtk_Button;
G : constant array(0 .. 1) of Guint := (17, 14);
D : constant array(0 .. 1) of Guint := (20, 17);
H : constant array(0 .. 1) of Guint := (17, 14);
B : constant array(0 .. 1) of Guint := (19, 16);
procedure affich0 (emet : access gtk_widget_record'class) is
begin
insert_text(Ecran, "0", pos); -- fonction issue de Gtk.Editable
end affich0;
procedure affich1 (emet : access gtk_widget_record'class) is
begin
insert_text(Ecran, "1", pos);
end affich1;
procedure affich_plus (emet : access gtk_widget_record'class) is
begin
insert_text(Ecran, "+", pos);
end affich_plus;
procedure effacer (emet : access gtk_widget_record'class) is
begin
delete_text(Ecran, 0, pos);
end effacer;
-- package traitement is new callback (gtk_widget_record);
type String_Ptr is access all String;
procedure Affich (Emet : access Gtk_Widget_Record'Class;
Data : String_Ptr) is
begin
Insert_Text(Ecran, Data.all , Pos);
end affich;
package Traitement is new Gtk.Handlers.User_Callback
(Widget_Type => Gtk_Widget_Record,
User_Type => String_Ptr);
package traitement_tools is new callback (gtk_widget_record);
begin
init;
-- Création de la fenetre
gtk_new(fenetre, window_toplevel);
set_size_request(fenetre, 400, 300);
set_position(fenetre, win_pos_center);
gtk_new(Table, 21, 25, true);
add(fenetre, Table);
-- Création d'un Frame "Affichage", suivi
-- de la Création de l'écran d'affichage
gtk_new(Frame_affich, "Affichage");
attach_defaults(Table, Frame_affich, 1, 24, 1, 6);
gtk_new(Ecran);
attach_defaults(Table, Ecran, 7, 13, 2, 3);
set_has_frame (Ecran, false);
set_editable (Ecran, False);
gtk_new(Affich_result);
attach_defaults(Table, Affich_result, 7, 23, 4, 5);
set_editable (Affich_result, False);
-- Création des boutons du frame "Opérations" - opérations usuelles
-- suivi de la création des boutons relatifs à ce frame
gtk_new(Frame_ope, "Operations");
attach_defaults(Table, frame_ope, 1, 12, 13, 20);
gtk_new(btn_plus, "+");
attach_defaults(Table, btn_plus, 3, 5, 15, 17);
--traitement.connect (btn_plus, "clicked", traitement.to_marshaller(affich_plus'access));
-- Création du Frame "Nombres" suivi de la
-- création des boutons "virgule" et "puissance de 10", suivi de
-- la création d'une boucle pour générer les x boutons chiffres
gtk_new(Frame_nomb, "Chiffres");
attach_defaults(Table, Frame_nomb, 13, 24, 7, 20);
gtk_new(btn_clear, "C");
attach_defaults(Table, btn_clear, 20, 23, 17, 19);
traitement_tools.connect (btn_clear, "clicked", traitement_tools.to_marshaller(effacer'access));
-- gtk_new(bouton0, "0");
-- attach_defaults(Table, bouton0, g(0), d(0), h(0), b(0));
-- traitement.connect (bouton0, "clicked", traitement.to_marshaller(affich0'access));
--
-- gtk_new(bouton1, "1");
-- attach_defaults(Table, bouton1, g(1), d(1), h(1), b(1));
-- traitement.connect (bouton1, "clicked", traitement.to_marshaller(affich1'access));
for J in Bouton'Range loop
Gtk_New(Bouton(J), Integer'Image(J));
Traitement.Connect(Bouton(J),
"clicked",
Traitement.To_Marshaller(Affich'Access),
new String'(Integer'Image(J)));
end loop;
for J in bouton'range loop
attach_defaults(Table, bouton(J), G(J), D(J), H(J), B(J));
end loop;
show_all(fenetre);
main;
end cessai; |
Partager