1 #ifndef UI_EDIT_H
2 #define UI_EDIT_H
3 
4 #include "panel.h"
5 
6 #include "../ui.h"
7 
8 /* TODO replace windows functions, multiline edits, add missing edit functions (ex: double click to select word)*/
9 
10 #include <stdbool.h>
11 #include <stdint.h>
12 
13 typedef struct scrollable SCROLLABLE;
14 
15 typedef struct edit_change {
16     bool     remove, padding;
17     uint16_t start, length;
18     char     data[];
19 } EDIT_CHANGE;
20 
21 typedef struct edit EDIT;
22 struct edit {
23     PANEL panel;
24 
25     bool multiline, mouseover, noborder, readonly, select_completely, vcentered, password;
26 
27     uint16_t mouseover_char, length;
28     uint16_t width, height;
29 
30     uint16_t      history_cur, history_length;
31     EDIT_CHANGE **history;
32 
33     SCROLLABLE *scroll;
34     char *      data;
35     size_t      data_size;
36 
37     MAYBE_I18NAL_STRING empty_str;
38     UI_ELEMENT_STYLE    style;
39 
40     void (*onenter)(EDIT *edit);
41     void (*onchange)(EDIT *edit);
42     void (*ontab)(EDIT *edit);
43     void (*onshifttab)(EDIT *edit);
44     void (*onlosefocus)(EDIT *edit);
45 };
46 
47 void edit_draw(EDIT *edit, int x, int y, int width, int height);
48 
49 bool edit_mmove(EDIT *edit, int x, int y, int width, int height, int mx, int my, int dx, int dy);
50 bool edit_mdown(EDIT *edit);
51 bool edit_dclick(EDIT *edit, bool triclick);
52 bool edit_mright(EDIT *edit);
53 bool edit_mwheel(EDIT *edit, int height, double d, bool smooth);
54 bool edit_mup(EDIT *edit);
55 bool edit_mleave(EDIT *edit);
56 
57 void edit_do(EDIT *edit, uint16_t start, uint16_t length, bool remove);
58 
59 void edit_press(void);
60 
61 void edit_char(uint32_t ch, bool control, uint8_t flags);
62 
63 int edit_selection(EDIT *edit, char *data, int len);
64 int edit_copy(char *data, int len);
65 void edit_paste(char *data, int len, bool select);
66 
67 bool  edit_active(void);
68 EDIT *edit_get_active(void);
69 
70 void edit_resetfocus(void);
71 void edit_setfocus(EDIT *edit);
72 void edit_setstr(EDIT *edit, char *str, uint16_t length);
73 void edit_setcursorpos(EDIT *edit, uint16_t pos);
74 uint16_t edit_getcursorpos(void);
75 
76 // set outloc and outlen to the mark range.
77 // returns 1 if the mark range is valid for the current edit,
78 // else 0.
79 // a mark range is valid when *outlen != 0 and there is an active edit.
80 bool edit_getmark(uint16_t *outloc, uint16_t *outlen);
81 void edit_setmark(uint16_t loc, uint16_t len);
82 
83 void edit_setselectedrange(uint16_t loc, uint16_t len);
84 
85 #endif // UI_EDIT_H
86