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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
|
--***************************************************************
-- 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;
with gtk.editable; use gtk.editable;
with p_calculs; use p_calculs;
--with p_calc_outils; use p_calc_outils;
--with p_calc_drawing_screen; use p_calc_drawing_screen;
with ada.strings.unbounded; use ada.strings.unbounded;
procedure cessai is
Table : gtk_table;
Fenetre : gtk_window;
Ecran, Ecran2, Ecran3, Affich_result : Gtk_GEntry;
Frame_affich, Frame_ope, Frame_nomb : gtk_frame;
btn_plus : Gtk_Button;
btn_clear, btn_exe : 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);
------------------------------------------
-- package aff_chiffres (spécification) --
------------------------------------------
package aff_chiffres is
procedure affich0 (emet : access gtk_widget_record'class);
procedure affich1 (emet : access gtk_widget_record'class);
end aff_chiffres;
----------------------------------
-- package aff_chiffres (corps) --
----------------------------------
package body aff_chiffres is
procedure affich0 (emet : access gtk_widget_record'class) is
begin
insert_text(Ecran, "0", pos); -- fonction issue de Gtk.Editable
insert_text(Ecran3, "0", pos);
end affich0;
procedure affich1 (emet : access gtk_widget_record'class) is
begin
insert_text(Ecran, "1", pos);
insert_text(Ecran3, "1", pos);
end affich1;
end aff_chiffres;
----------------------------------------
-- package aff_outils (spécification) --
----------------------------------------
package aff_outils is
-- Conversions de types --
function Int_Str (X : Integer) return string;
function int_ustr (X : integer) return unbounded_string;
function ustr_int (X : unbounded_string) return integer;
function ustr_str (X : unbounded_string) return string;
-- opérations élémentaires --
procedure Add (X, Y : integer);
procedure Sou (X, Y : Integer);
procedure Mul (X, Y : Integer);
procedure Div (X, Y : Integer);
-- Actions --
procedure calculer (N1, N2 : integer);
procedure affich_plus (emet : access gtk_widget_record'class);
procedure effacer (emet : access gtk_widget_record'class);
procedure aff_resultat (emet : access gtk_widget_record'class);
end aff_outils;
----------------------------------------
-- package aff_outils (spécification) --
----------------------------------------
package p_pile is
-- Empiler / Dépiler --
procedure empiler (X : integer);
function depiler return integer;
procedure empiler_ustr (X : unbounded_string);
function depiler_ustr return unbounded_string;
end p_pile;
--------------------------------
-- package aff_outils (corps) --
--------------------------------
package body aff_outils is
use p_pile;
-- Conversions de types --
function Int_Str (X : Integer) return string is
begin
return integer'image(X);
end Int_Str;
function int_ustr (X : integer) return unbounded_string is
begin
return ada.strings.unbounded.to_unbounded_string(integer'image(X));
end int_ustr;
function ustr_int (X : unbounded_string) return integer is
begin
return integer'value(ada.strings.unbounded.to_string(x));
end ustr_int;
function ustr_str (X : unbounded_string) return string is
begin
return ada.strings.unbounded.to_string(X);
end ustr_str;
-- Actions --
procedure affich_plus (emet : access gtk_widget_record'class) is
begin
insert_text(Ecran2, "+", pos);
end affich_plus;
procedure effacer (emet : access gtk_widget_record'class) is
begin
delete_text(Ecran, 0, pos);
end effacer;
-- Opérations élémentaires --
procedure Add (X, Y : integer) is
resultat : integer;
begin
resultat := X + Y;
empiler(resultat);
end Add;
procedure Sou (X, Y : integer) is
resultat : integer;
begin
resultat := X - Y;
empiler(resultat);
end Sou;
procedure Mul (X, Y : Integer) is
resultat : integer;
begin
resultat := X * Y;
empiler(resultat);
end Mul;
procedure Div (X, Y : Integer) is
resultat : integer;
begin
resultat := X / Y;
empiler(resultat);
end Div;
procedure calculer (N1, N2 : integer) is
use p_pile;
E1, E3, res : Integer;
B : character;
N : unbounded_string;
resultat : string := "";
begin
E1 := integer'value(get_chars (Ecran, 0, 0));
B := character'value(get_chars(Ecran2, 0, 0));
E3 := integer'value(get_chars (Ecran3, 0, 0));
case B is
when '+' => add(E1, E3);
when '-' => sou(E1, E3);
when '*' => mul(E1, E3);
when '/' => div(E1, E3);
when others => null;
end case;
res := depiler;
n := Int_UStr(res);
empiler_Ustr(n);
end calculer;
procedure aff_resultat (emet : access gtk_widget_record'class) is
b : unbounded_string;
c : string := "";
begin
b := depiler_ustr;
c := ustr_str(b);
insert_text (Affich_result, c, pos);
end aff_resultat;
end aff_outils;
--------------------------------
-- package aff_outils (corps) --
--------------------------------
package body p_pile is
max : constant := 3;
pile : array (1 .. max) of integer;
pile_ustr : array (1 .. max) of unbounded_string;
sommet, sommet_ustr : integer range 0 .. max;
-- Empiler / Dépiler --
procedure empiler (x : integer) is
begin
sommet := sommet + 1;
pile (sommet) := x;
end empiler;
function depiler return integer is
begin
sommet := sommet - 1;
return pile (sommet + 1);
end depiler;
procedure empiler_ustr (x : unbounded_string) is
begin
sommet_ustr := sommet_ustr + 1;
pile_ustr (sommet_ustr) := X;
end empiler_ustr;
function depiler_ustr return unbounded_string is
begin
sommet_ustr := sommet_ustr - 1;
return pile_ustr (sommet_ustr + 1);
end depiler_ustr;
begin
sommet := 0;
sommet_ustr := 0;
end p_pile;
package traitement is new callback (gtk_widget_record);
package traitement_tools 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);
--use aff_outils;
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, 2, 9, 2, 3);
set_has_frame (Ecran, false);
set_editable (Ecran, False);
gtk_new(Ecran2);
attach_defaults(Table, Ecran2, 9, 12, 2, 3);
set_has_frame (Ecran2, false);
set_editable (Ecran2, False);
gtk_new(Ecran3);
attach_defaults(Table, Ecran3, 12, 19, 2, 3);
set_has_frame (Ecran3, false);
set_editable (Ecran3, False);
gtk_new(Affich_result);
attach_defaults(Table, Affich_result, 2, 19, 4, 5);
set_editable (Affich_result, False);
gtk_new(btn_exe, "EXE");
attach_defaults(Table, btn_exe, 20, 23, 2, 5);
traitement_tools.connect (btn_exe, "clicked", traitement_tools.to_marshaller(aff_outils.aff_resultat'access));
-- 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_tools.connect (btn_plus, "clicked", traitement_tools.to_marshaller(aff_outils.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(aff_outils.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(aff_chiffres.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(aff_chiffres.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'(get_label(bouton(J)))); --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