1 /* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */ 2 3 #ifndef __UI_SELECTION_H__ 4 #define __UI_SELECTION_H__ 5 6 #include <pobl/bl_types.h> /* u_int */ 7 #include <vt_str.h> 8 9 typedef enum { 10 SEL_CHAR = 0x1, 11 SEL_WORD = 0x2, 12 SEL_LINE = 0x3, 13 14 } ui_sel_type_t; 15 16 typedef struct ui_sel_event_listener { 17 void *self; 18 int (*select_in_window)(void *, vt_char_t **, u_int *, int, int, int, int, int); 19 void (*reverse_color)(void *, int, int, int, int, int); 20 void (*restore_color)(void *, int, int, int, int, int); 21 22 } ui_sel_event_listener_t; 23 24 typedef struct ui_selection { 25 ui_sel_event_listener_t *sel_listener; 26 27 vt_char_t *sel_str; 28 u_int sel_len; 29 30 /* 31 * Be careful that value of col must be munis in rtl line. 32 * +-----------------------------+ 33 * | a a a a a a a|<= RTL line 34 * -1 -2 -3 -4 -5 -6 -7 <= index 35 */ 36 37 int base_col_l; 38 int base_row_l; 39 int base_col_r; 40 int base_row_r; 41 int beg_col; 42 int beg_row; 43 int end_col; 44 int end_row; 45 int lock_col; 46 int lock_row; 47 48 int prev_col; 49 int prev_row; 50 51 int8_t is_selecting; /* ui_sel_type_t is stored */ 52 int8_t is_reversed; 53 int8_t is_locked; 54 int8_t is_rect; 55 56 } ui_selection_t; 57 58 void ui_sel_init(ui_selection_t *sel, ui_sel_event_listener_t *listener); 59 60 void ui_sel_final(ui_selection_t *sel); 61 62 void ui_start_selection(ui_selection_t *sel, int col_l, int row_l, int col_r, int row_r, 63 ui_sel_type_t type, int is_rect); 64 65 int ui_selecting(ui_selection_t *sel, int col, int row); 66 67 int ui_stop_selecting(ui_selection_t *sel); 68 69 int ui_restore_selected_region_color_except_logs(ui_selection_t *sel); 70 71 int ui_reverse_selected_region_color_except_logs(ui_selection_t *sel); 72 73 int ui_restore_selected_region_color(ui_selection_t *sel); 74 75 int ui_reverse_selected_region_color(ui_selection_t *sel); 76 77 int ui_sel_clear(ui_selection_t *sel); 78 79 int ui_selected_region_is_changed(ui_selection_t *sel, int col, int row, u_int base); 80 81 void ui_sel_line_scrolled_out(ui_selection_t *sel, int min_row); 82 83 #define ui_is_selecting(sel) ((sel)->is_selecting) 84 85 #define ui_sel_is_reversed(sel) ((sel)->is_reversed) 86 87 int ui_is_after_sel_right_base_pos(ui_selection_t *sel, int col, int row); 88 89 int ui_is_before_sel_left_base_pos(ui_selection_t *sel, int col, int row); 90 91 void ui_sel_lock(ui_selection_t *sel); 92 93 #endif 94