1package body agar.gui.widget.editable is 2 3 package cbinds is 4 procedure set_static 5 (editable : editable_access_t; 6 enable : c.int); 7 pragma import (c, set_static, "AG_EditableSetStatic"); 8 9 procedure set_password 10 (editable : editable_access_t; 11 enable : c.int); 12 pragma import (c, set_password, "AG_EditableSetPassword"); 13 14 procedure set_integer_only 15 (editable : editable_access_t; 16 enable : c.int); 17 pragma import (c, set_integer_only, "AG_EditableSetIntOnly"); 18 19 procedure set_float_only 20 (editable : editable_access_t; 21 enable : c.int); 22 pragma import (c, set_float_only, "AG_EditableSetFltOnly"); 23 24 procedure size_hint 25 (editable : editable_access_t; 26 text : cs.chars_ptr); 27 pragma import (c, size_hint, "AG_EditableSizeHint"); 28 29 procedure size_hint_pixels 30 (editable : editable_access_t; 31 width : c.int; 32 height : c.int); 33 pragma import (c, size_hint_pixels, "AG_EditableSizeHintPixels"); 34 35 function map_position 36 (editable : editable_access_t; 37 x : c.int; 38 y : c.int; 39 pos : access c.int; 40 absolute : c.int) return c.int; 41 pragma import (c, map_position, "AG_EditableMapPosition"); 42 43 procedure move_cursor 44 (editable : editable_access_t; 45 x : c.int; 46 y : c.int; 47 absolute : c.int); 48 pragma import (c, move_cursor, "AG_EditableMoveCursor"); 49 50 function get_cursor_position (editable : editable_access_t) return c.int; 51 pragma import (c, get_cursor_position, "AG_EditableGetCursorPos"); 52 53 function set_cursor_position 54 (editable : editable_access_t; 55 index : c.int) return c.int; 56 pragma import (c, set_cursor_position, "AG_EditableSetCursorPos"); 57 58 procedure set_string 59 (editable : editable_access_t; 60 text : cs.chars_ptr); 61 pragma import (c, set_string, "AG_EditableSetString"); 62 63 function get_integer (editable : editable_access_t) return c.int; 64 pragma import (c, get_integer, "AG_EditableInt"); 65 66 function get_float (editable : editable_access_t) return c.c_float; 67 pragma import (c, get_float, "AG_EditableFlt"); 68 69 function get_long_float (editable : editable_access_t) return c.double; 70 pragma import (c, get_long_float, "AG_EditableDbl"); 71 end cbinds; 72 73 procedure set_static 74 (editable : editable_access_t; 75 enable : boolean) is 76 begin 77 if enable then 78 cbinds.set_static (editable => editable, enable => 1); 79 else 80 cbinds.set_static (editable => editable, enable => 0); 81 end if; 82 end set_static; 83 84 procedure set_password 85 (editable : editable_access_t; 86 enable : boolean) is 87 begin 88 if enable then 89 cbinds.set_password (editable => editable, enable => 1); 90 else 91 cbinds.set_password (editable => editable, enable => 0); 92 end if; 93 end set_password; 94 95 procedure set_integer_only 96 (editable : editable_access_t; 97 enable : boolean) is 98 begin 99 if enable then 100 cbinds.set_integer_only (editable => editable, enable => 1); 101 else 102 cbinds.set_integer_only (editable => editable, enable => 0); 103 end if; 104 end set_integer_only; 105 106 procedure set_float_only 107 (editable : editable_access_t; 108 enable : boolean) is 109 begin 110 if enable then 111 cbinds.set_float_only (editable => editable, enable => 1); 112 else 113 cbinds.set_float_only (editable => editable, enable => 0); 114 end if; 115 end set_float_only; 116 117 procedure size_hint 118 (editable : editable_access_t; 119 text : string) 120 is 121 ca_text : aliased c.char_array := c.to_c (text); 122 begin 123 cbinds.size_hint 124 (editable => editable, 125 text => cs.to_chars_ptr (ca_text'unchecked_access)); 126 end size_hint; 127 128 procedure size_hint_pixels 129 (editable : editable_access_t; 130 width : positive; 131 height : positive) is 132 begin 133 cbinds.size_hint_pixels 134 (editable => editable, 135 width => c.int (width), 136 height => c.int (height)); 137 end size_hint_pixels; 138 139 -- cursor manipulation 140 141 procedure map_position 142 (editable : editable_access_t; 143 x : integer; 144 y : integer; 145 index : out natural; 146 pos : out cursor_pos_t; 147 absolute : boolean) 148 is 149 c_abs : c.int := 0; 150 c_pos : aliased c.int; 151 c_ind : c.int; 152 begin 153 if absolute then c_abs := 1; end if; 154 c_ind := cbinds.map_position 155 (editable => editable, 156 x => c.int (x), 157 y => c.int (y), 158 pos => c_pos'unchecked_access, 159 absolute => c_abs); 160 index := natural (c_ind); 161 pos := cursor_pos_t'val (c_pos); 162 end map_position; 163 164 procedure move_cursor 165 (editable : editable_access_t; 166 x : integer; 167 y : integer; 168 absolute : boolean) 169 is 170 c_abs : c.int := 0; 171 begin 172 if absolute then c_abs := 1; end if; 173 cbinds.move_cursor 174 (editable => editable, 175 x => c.int (x), 176 y => c.int (y), 177 absolute => c_abs); 178 end move_cursor; 179 180 function get_cursor_position (editable : editable_access_t) return natural is 181 begin 182 return natural (cbinds.get_cursor_position (editable)); 183 end get_cursor_position; 184 185 function set_cursor_position 186 (editable : editable_access_t; 187 index : integer) return integer is 188 begin 189 return integer (cbinds.set_cursor_position (editable, c.int (index))); 190 end set_cursor_position; 191 192 -- text manipulation 193 194 procedure set_string 195 (editable : editable_access_t; 196 text : string) 197 is 198 ca_text : aliased c.char_array := c.to_c (text); 199 begin 200 cbinds.set_string (editable, cs.to_chars_ptr (ca_text'unchecked_access)); 201 end set_string; 202 203 function get_integer (editable : editable_access_t) return integer is 204 begin 205 return integer (cbinds.get_integer (editable)); 206 end get_integer; 207 208 function get_float (editable : editable_access_t) return float is 209 begin 210 return float (cbinds.get_float (editable)); 211 end get_float; 212 213 function get_long_float (editable : editable_access_t) return long_float is 214 begin 215 return long_float (cbinds.get_long_float (editable)); 216 end get_long_float; 217 218 function widget (editable : editable_access_t) return widget_access_t is 219 begin 220 return editable.widget'access; 221 end widget; 222 223end agar.gui.widget.editable; 224