aboutsummaryrefslogtreecommitdiff
path: root/src/base_internal.h
blob: 0ece0bf742f28906c5ac9c0d1094244e567f9df1 (plain)
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
146
147
148
149
150
151
/*
 * Copyright (c) 2018-2019 Hanspeter Portner (dev@open-music-kontrollers.ch)
 *
 * This is free software: you can redistribute it and/or modify
 * it under the terms of the Artistic License 2.0 as published by
 * The Perl Foundation.
 *
 * This source is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * Artistic License 2.0 for more details.
 *
 * You should have received a copy of the Artistic License 2.0
 * along the source as a COPYING file. If not, obtain it from
 * http://www.perlfoundation.org/artistic_license_2_0.
 */

#include <stdatomic.h>

#include <d2tk/base.h>
#include <d2tk/hash.h>
#include "core_internal.h"

#define _D2TK_MAX_ATOM 0x1000
#define _D2TK_MASK_ATOMS (_D2TK_MAX_ATOM - 1)

typedef enum _d2tk_atom_type_t {
	D2TK_ATOM_NONE,
	D2TK_ATOM_SCROLL,
	D2TK_ATOM_PANE,
	D2TK_ATOM_FLOW,
	D2TK_ATOM_FLOW_NODE,
	D2TK_ATOM_FLOW_ARC,
	D2TK_ATOM_PTY,
	D2TK_ATOM_LINEEDIT,
#if D2TK_EVDEV
	D2TK_ATOM_VKB,
#endif
} d2tk_atom_type_t;

typedef enum _d2tk_atom_event_type_t {
	D2TK_ATOM_EVENT_NONE,
	D2TK_ATOM_EVENT_FD,
	D2TK_ATOM_EVENT_DEINIT
} d2tk_atom_event_type_t;

typedef struct _d2tk_flip_t d2tk_flip_t;
typedef struct _d2tk_atom_t d2tk_atom_t;
typedef int (*d2tk_atom_event_t)(d2tk_atom_event_type_t event, void *data);

struct _d2tk_flip_t {
	d2tk_id_t old;
	d2tk_id_t cur;
};

struct _d2tk_atom_t {
	d2tk_id_t id;
	d2tk_atom_type_t type;
	void *body;
	d2tk_atom_event_t event;
};

struct _d2tk_base_t {
	d2tk_flip_t hotitem;
	d2tk_flip_t activeitem;
	d2tk_flip_t focusitem;
	d2tk_id_t lastitem;

	bool not_first_time;
	bool unicode_mode;
	uint32_t unicode_acc;

	struct {
		d2tk_coord_t x;
		d2tk_coord_t y;
		d2tk_coord_t ox;
		d2tk_coord_t oy;
		d2tk_coord_t dx;
		d2tk_coord_t dy;
		d2tk_butmask_t mask;
		d2tk_butmask_t mask_prev;
	} mouse;

	struct {
		int32_t odx;
		int32_t ody;
		int32_t dx;
		int32_t dy;
	} scroll;

	struct {
		size_t nchars;
		utf8_int32_t chars [32];
		unsigned keymod;
		d2tk_keymask_t mask;
		d2tk_keymask_t mask_prev;
		d2tk_modmask_t mod;
	} keys;

	struct {
		char text_in [1024];
		char text_out [1024];
	} edit;

	struct {
		char buf [1024];
		size_t len;
		d2tk_coord_t h;
	} tooltip;

	const d2tk_style_t *style;

	atomic_bool again;
	bool clear_focus;
	bool focused;

	d2tk_core_t *core;

	d2tk_atom_t atoms [_D2TK_MAX_ATOM];
};

extern const size_t d2tk_atom_body_flow_sz;
extern const size_t d2tk_atom_body_pane_sz;
extern const size_t d2tk_atom_body_scroll_sz;
extern const size_t d2tk_atom_body_pty_sz;
extern const size_t d2tk_atom_body_lineedit_sz;
#if D2TK_EVDEV
extern const size_t d2tk_atom_body_vkb_sz;
#endif

void *
_d2tk_base_get_atom(d2tk_base_t *base, d2tk_id_t id, d2tk_atom_type_t type,
	d2tk_atom_event_t event);

d2tk_state_t
_d2tk_base_is_active_hot_vertical_scroll(d2tk_base_t *base);

d2tk_state_t
_d2tk_base_is_active_hot_horizontal_scroll(d2tk_base_t *base);

void
_d2tk_base_clear_chars(d2tk_base_t *base);

d2tk_state_t
_d2tk_base_tooltip_draw(d2tk_base_t *base, ssize_t lbl_len, const char *lbl,
	d2tk_coord_t h);

d2tk_pty_t *
d2tk_pty_begin_state(d2tk_base_t *base, d2tk_id_t id, d2tk_state_t state,
	d2tk_base_pty_cb_t cb, void *data, d2tk_coord_t height,
	const d2tk_rect_t *rect, d2tk_flag_t flags, d2tk_pty_t *pty);