-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathventana_conversor_pkg-callbacks.adb
145 lines (110 loc) · 3.66 KB
/
ventana_conversor_pkg-callbacks.adb
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
with System; use System;
with Glib; use Glib;
with Glib.Convert; use Glib.Convert;
with Gdk.Event; use Gdk.Event;
with Gdk.Types; use Gdk.Types;
with Gtk.Accel_Group; use Gtk.Accel_Group;
with Gtk.Object; use Gtk.Object;
with Gtk.Enums; use Gtk.Enums;
with Gtk.Style; use Gtk.Style;
with Gtk.Widget; use Gtk.Widget;
with Gtk.Gentry; use Gtk.Gentry;
with Gtk.Main;
with Ventana_Conversor_Pkg; use Ventana_Conversor_Pkg;
with Ventana;
with Os;
with Ada.Integer_Text_Io; use Ada.Integer_Text_Io;
with Ada.Strings.Fixed; use Ada.Strings; use Ada.Strings.Fixed;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_Io; use Ada.Text_Io;
with Ada.Exceptions;
with Gnat.Os_Lib;
package body Ventana_Conversor_Pkg.Callbacks is
use Gtk.Arguments;
function Hex_A_Dec (Hex : String) return String is
Decimal : String (1 .. 100);
begin
Put (To => Decimal,
Item => Integer'Value ("16#" & Hex & "#"));
return Trim (Side => Left, Source => Decimal);
exception
when Constraint_Error =>
return "Error";
end Hex_A_Dec;
procedure Convertir_Hex_Dec
is
Ventana_Conversor : Ventana_Conversor_Access;
begin
Ventana_Conversor := Ventana.Ref;
declare
Hex : constant String := Locale_From_UTF8
(Get_Text (Ventana_Conversor.Entry_Hex));
Inicio : Natural := Hex'First;
Espacio : Natural := Hex'First;
Dec : Unbounded_String := Null_Unbounded_String;
begin
while Inicio in Hex'range loop
Espacio := Ada.Strings.Fixed.Index
(Source => Hex (Inicio .. Hex'Last), Pattern => " ");
if Espacio /= 0 then
Dec := Dec & Hex_A_Dec (Hex (Inicio .. Espacio - 1)) & ' ';
Inicio := Index_Non_Blank (Source => Hex (Espacio .. Hex'Last));
else
Dec := Dec & Hex_A_Dec (Hex (Inicio .. Hex'Last));
Inicio := 0;
end if;
end loop;
Set_Text (The_Entry => Ventana_Conversor.Entry_Dec,
Text => Locale_To_UTF8 (To_String (Dec)));
end;
end Convertir_Hex_Dec;
-----------------------
-- Convertir_Hex_Dec --
-----------------------
procedure Convertir_Hex_Dec
(Object : access Gtk_Button_Record'Class)
is
begin
Convertir_Hex_Dec;
end Convertir_Hex_Dec;
-----------------------
-- Convertir_Hex_Dec --
-----------------------
procedure Convertir_Hex_Dec
(Object : access Gtk_Entry_Record'Class)
is
begin
Convertir_Hex_Dec;
end Convertir_Hex_Dec;
------------------
-- Imprimir_Hex --
------------------
procedure Imprimir_Hex
(Object : access Gtk_Button_Record'Class)
is
Ventana_Conversor : Ventana_Conversor_Access := Ventana.Ref;
Texto_Dec : constant String :=
Locale_From_UTF8 (Get_Text (Ventana_Conversor.Entry_Dec));
Texto_Hex : constant String :=
Locale_From_UTF8 (Get_Text (Ventana_Conversor.Entry_Hex));
begin
Os.Imprimir ("Hexadecimal: " & Texto_Hex & ASCII.LF &
"Decimal: " & Texto_Dec);
exception
when Ex : others =>
Put_Line (Current_Error, "Excepcion en Imprimir_Hex: " &
Ada.Exceptions.Exception_Information (Ex));
end Imprimir_Hex;
-------------------
-- Gtk_Main_Quit --
-------------------
function Gtk_Main_Quit
(Object : access Gtk_Widget_Record'Class;
Params : Gtk.Arguments.Gtk_Args) return Boolean
is
Arg1 : Gdk_Event := To_Event (Params, 1);
begin
Gtk.Main.Main_Quit;
return False;
end Gtk_Main_Quit;
end Ventana_Conversor_Pkg.Callbacks;