1with agar.core.timeout; 2with agar.core.types; 3 4package agar.gui.widget.editable is 5 use type c.unsigned; 6 7 type encoding_t is (ENCODING_UTF8, ENCODING_ASCII); 8 for encoding_t use (ENCODING_UTF8 => 0, ENCODING_ASCII => 1); 9 for encoding_t'size use c.unsigned'size; 10 pragma convention (c, encoding_t); 11 12 type flags_t is new c.unsigned; 13 EDITABLE_HFILL : constant flags_t := 16#00001#; 14 EDITABLE_VFILL : constant flags_t := 16#00002#; 15 EDITABLE_EXPAND : constant flags_t := EDITABLE_HFILL or EDITABLE_VFILL; 16 EDITABLE_MULTILINE : constant flags_t := 16#00004#; 17 EDITABLE_BLINK_ON : constant flags_t := 16#00008#; 18 EDITABLE_PASSWORD : constant flags_t := 16#00010#; 19 EDITABLE_ABANDON_FOCUS : constant flags_t := 16#00020#; 20 EDITABLE_INT_ONLY : constant flags_t := 16#00040#; 21 EDITABLE_FLT_ONLY : constant flags_t := 16#00080#; 22 EDITABLE_CATCH_TAB : constant flags_t := 16#00100#; 23 EDITABLE_CURSOR_MOVING : constant flags_t := 16#00200#; 24 EDITABLE_NOSCROLL : constant flags_t := 16#00800#; 25 EDITABLE_NOSCROLL_ONCE : constant flags_t := 16#01000#; 26 EDITABLE_MARKPREF : constant flags_t := 16#02000#; 27 EDITABLE_STATIC : constant flags_t := 16#04000#; 28 EDITABLE_NOEMACS : constant flags_t := 16#08000#; 29 EDITABLE_NOWORDSEEK : constant flags_t := 16#10000#; 30 EDITABLE_NOLATIN1 : constant flags_t := 16#20000#; 31 32 string_max : constant := 1024; 33 type string_t is array (1 .. string_max) of aliased c.char; 34 pragma convention (c, string_t); 35 36 type editable_t is limited private; 37 type editable_access_t is access all editable_t; 38 pragma convention (c, editable_access_t); 39 40 type cursor_pos_t is (CURSOR_BEFORE, CURSOR_IN, CURSOR_AFTER); 41 for cursor_pos_t use (CURSOR_BEFORE => -1, CURSOR_IN => 0, CURSOR_AFTER => 1); 42 43 -- API 44 45 function allocate 46 (parent : widget_access_t; 47 flags : flags_t) return editable_access_t; 48 pragma import (c, allocate, "AG_EditableNew"); 49 50 -- missing: bind_utf8 - unsure of how to bind 51 -- missing: bind_ascii 52 53 procedure set_static 54 (editable : editable_access_t; 55 enable : boolean); 56 pragma inline (set_static); 57 58 procedure set_password 59 (editable : editable_access_t; 60 enable : boolean); 61 pragma inline (set_password); 62 63 procedure set_integer_only 64 (editable : editable_access_t; 65 enable : boolean); 66 pragma inline (set_integer_only); 67 68 procedure set_float_only 69 (editable : editable_access_t; 70 enable : boolean); 71 pragma inline (set_float_only); 72 73 procedure size_hint 74 (editable : editable_access_t; 75 text : string); 76 pragma inline (size_hint); 77 78 procedure size_hint_pixels 79 (editable : editable_access_t; 80 width : positive; 81 height : positive); 82 pragma inline (size_hint_pixels); 83 84 -- cursor manipulation 85 86 procedure map_position 87 (editable : editable_access_t; 88 x : integer; 89 y : integer; 90 index : out natural; 91 pos : out cursor_pos_t; 92 absolute : boolean); 93 pragma inline (map_position); 94 95 procedure move_cursor 96 (editable : editable_access_t; 97 x : integer; 98 y : integer; 99 absolute : boolean); 100 pragma inline (move_cursor); 101 102 function get_cursor_position (editable : editable_access_t) return natural; 103 pragma inline (get_cursor_position); 104 105 function set_cursor_position 106 (editable : editable_access_t; 107 index : integer) return integer; 108 pragma inline (set_cursor_position); 109 110 -- text manipulation 111 112 procedure set_string 113 (editable : editable_access_t; 114 text : string); 115 pragma inline (set_string); 116 117 procedure clear_string (editable : editable_access_t); 118 pragma import (c, clear_string, "AG_EditableClearString"); 119 120 procedure buffer_changed (editable : editable_access_t); 121 pragma import (c, buffer_changed, "AG_EditableBufferChanged"); 122 123 function get_integer (editable : editable_access_t) return integer; 124 pragma inline (get_integer); 125 126 function get_float (editable : editable_access_t) return float; 127 pragma inline (get_float); 128 129 function get_long_float (editable : editable_access_t) return long_float; 130 pragma inline (get_long_float); 131 132 function widget (editable : editable_access_t) return widget_access_t; 133 pragma inline (widget); 134 135private 136 137 type editable_t is record 138 widget : aliased widget_t; 139 140 flags : flags_t; 141 142 encoding : encoding_t; 143 str : string_t; 144 width_pre : c.int; 145 height_pre : c.int; 146 pos : c.int; 147 compose : agar.core.types.uint32_t; 148 x_cursor : c.int; 149 y_cursor : c.int; 150 x_cursor_pref : c.int; 151 152 x_sel1 : c.int; 153 x_sel2 : c.int; 154 sel_edit : c.int; 155 156 to_delay : agar.core.timeout.timeout_t; 157 to_repeat : agar.core.timeout.timeout_t; 158 to_blink : agar.core.timeout.timeout_t; 159 160 x : c.int; 161 x_max : c.int; 162 y : c.int; 163 y_max : c.int; 164 y_vis : c.int; 165 wheel_ticks : agar.core.types.uint32_t; 166 repeat_key : c.int; 167 repeat_mod : c.int; 168 repeat_unicode : agar.core.types.uint32_t; 169 ucs_buffer : access agar.core.types.uint32_t; 170 ucs_length : c.unsigned; 171 r : agar.gui.rect.rect_t; 172 end record; 173 pragma convention (c, editable_t); 174 175end agar.gui.widget.editable; 176