1 /*
2  *  STFL - The Structured Terminal Forms Language/Library
3  *  Copyright (C) 2006, 2007  Clifford Wolf <clifford@clifford.at>
4  *
5  *  This library is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU Lesser General Public
7  *  License as published by the Free Software Foundation; either
8  *  version 3 of the License, or (at your option) any later version.
9  *
10  *  This library is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *  Lesser General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Lesser General Public
16  *  License along with this library; if not, write to the Free Software
17  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18  *  MA 02110-1301 USA
19  *
20  *  stfl_internals.h: The STFL C header file (Internal STFL APIs)
21  */
22 
23 #ifndef STFL__INTERNALS_H
24 #define STFL__INTERNALS_H 1
25 
26 #ifdef  __cplusplus
27 extern "C" {
28 #endif
29 
30 #include "stfl.h"
31 #include </usr/local/include/ncurses/ncurses.h>
32 #include <pthread.h>
33 
34 struct stfl_widget_type;
35 struct stfl_kv;
36 struct stfl_widget;
37 
38 struct stfl_widget_type {
39 	wchar_t *name;
40 
41 	void (*f_init)(struct stfl_widget *w);
42 	void (*f_done)(struct stfl_widget *w);
43 
44 	void (*f_enter)(struct stfl_widget *w, struct stfl_form *f);
45 	void (*f_leave)(struct stfl_widget *w, struct stfl_form *f);
46 
47 	void (*f_prepare)(struct stfl_widget *w, struct stfl_form *f);
48 	void (*f_draw)(struct stfl_widget *w, struct stfl_form *f, WINDOW *win);
49 	int (*f_process)(struct stfl_widget *w, struct stfl_widget *fw, struct stfl_form *f, wchar_t ch, int is_function_key);
50 };
51 
52 struct stfl_kv {
53 	struct stfl_kv *next;
54 	struct stfl_widget *widget;
55 	wchar_t *key, *value, *name;
56 	int id;
57 };
58 
59 struct stfl_widget {
60 	struct stfl_widget *parent;
61 	struct stfl_widget *next_sibling;
62 	struct stfl_widget *first_child;
63 	struct stfl_widget *last_child;
64 	struct stfl_kv *kv_list;
65 	struct stfl_widget_type *type;
66 	int id, x, y, w, h, min_w, min_h, cur_x, cur_y;
67 	int parser_indent, allow_focus;
68 	int setfocus;
69 	void *internal_data;
70 	wchar_t *name, *cls;
71 };
72 
73 struct stfl_event {
74 	struct stfl_event *next;
75 	wchar_t *event;
76 };
77 
78 struct stfl_form {
79 	struct stfl_widget *root;
80 	int current_focus_id;
81 	int cursor_x, cursor_y;
82 	struct stfl_event *event_queue;
83 	wchar_t *event;
84 	pthread_mutex_t mtx;
85 };
86 
87 extern int stfl_colorpair_counter;
88 
89 extern struct stfl_widget_type *stfl_widget_types[];
90 
91 extern struct stfl_widget_type stfl_widget_type_label;
92 extern struct stfl_widget_type stfl_widget_type_input;
93 extern struct stfl_widget_type stfl_widget_type_vbox;
94 extern struct stfl_widget_type stfl_widget_type_hbox;
95 extern struct stfl_widget_type stfl_widget_type_table;
96 extern struct stfl_widget_type stfl_widget_type_tablebr;
97 extern struct stfl_widget_type stfl_widget_type_list;
98 extern struct stfl_widget_type stfl_widget_type_listitem;
99 extern struct stfl_widget_type stfl_widget_type_textview;
100 extern struct stfl_widget_type stfl_widget_type_textedit;
101 extern struct stfl_widget_type stfl_widget_type_checkbox;
102 
103 extern struct stfl_widget *stfl_widget_new(const wchar_t *type);
104 extern void stfl_widget_free(struct stfl_widget *w);
105 
106 extern struct stfl_kv *stfl_widget_setkv_int(struct stfl_widget *w, const wchar_t *key, int value);
107 extern struct stfl_kv *stfl_widget_setkv_str(struct stfl_widget *w, const wchar_t *key, const wchar_t *value);
108 
109 extern struct stfl_kv *stfl_setkv_by_name_int(struct stfl_widget *w, const wchar_t *name, int value);
110 extern struct stfl_kv *stfl_setkv_by_name_str(struct stfl_widget *w, const wchar_t *name, const wchar_t *value);
111 
112 extern struct stfl_kv *stfl_widget_getkv(struct stfl_widget *w, const wchar_t *key);
113 extern int stfl_widget_getkv_int(struct stfl_widget *w, const wchar_t *key, int defval);
114 extern const wchar_t *stfl_widget_getkv_str(struct stfl_widget *w, const wchar_t *key, const wchar_t *defval);
115 
116 extern int stfl_getkv_by_name_int(struct stfl_widget *w, const wchar_t *name, int defval);
117 extern const wchar_t *stfl_getkv_by_name_str(struct stfl_widget *w, const wchar_t *name, const wchar_t *defval);
118 
119 extern struct stfl_widget *stfl_widget_by_name(struct stfl_widget *w, const wchar_t *name);
120 extern struct stfl_widget *stfl_widget_by_id(struct stfl_widget *w, int id);
121 
122 extern struct stfl_kv *stfl_kv_by_name(struct stfl_widget *w, const wchar_t *name);
123 extern struct stfl_kv *stfl_kv_by_id(struct stfl_widget *w, int id);
124 
125 extern struct stfl_widget *stfl_find_child_tree(struct stfl_widget *w, struct stfl_widget *c);
126 extern struct stfl_widget *stfl_find_first_focusable(struct stfl_widget *w);
127 extern int stfl_switch_focus(struct stfl_widget *old_fw, struct stfl_widget *new_fw, struct stfl_form *f);
128 
129 extern int stfl_focus_prev(struct stfl_widget *w, struct stfl_widget *old_fw, struct stfl_form *f);
130 extern int stfl_focus_next(struct stfl_widget *w, struct stfl_widget *old_fw, struct stfl_form *f);
131 
132 extern struct stfl_form *stfl_form_new();
133 extern void stfl_form_event(struct stfl_form *f, wchar_t *event);
134 extern void stfl_form_run(struct stfl_form *f, int timeout);
135 extern void stfl_form_reset();
136 extern void stfl_form_free(struct stfl_form *f);
137 extern void stfl_form_redraw();
138 
139 extern void stfl_check_setfocus(struct stfl_form *f, struct stfl_widget *w);
140 
141 extern struct stfl_widget *stfl_parser(const wchar_t *text);
142 extern struct stfl_widget *stfl_parser_file(const char *filename);
143 
144 extern wchar_t *stfl_quote_backend(const wchar_t *text);
145 extern wchar_t *stfl_widget_dump(struct stfl_widget *w, const wchar_t *prefix, int focus_id);
146 extern wchar_t *stfl_widget_text(struct stfl_widget *w);
147 
148 extern void stfl_style(WINDOW *win, const wchar_t *style);
149 extern void stfl_widget_style(struct stfl_widget *w, struct stfl_form *f, WINDOW *win);
150 
151 extern wchar_t *stfl_keyname(wchar_t ch, int isfunckey);
152 extern int stfl_matchbind(struct stfl_widget *w, wchar_t ch, int isfunckey, wchar_t *name, wchar_t *auto_desc);
153 
154 extern unsigned int stfl_print_richtext(struct stfl_widget *w, WINDOW *win, unsigned int y, unsigned int x, const wchar_t * text, unsigned int width, const wchar_t * style, int has_focus);
155 
156 #ifdef __cplusplus
157 }
158 #endif
159 
160 #endif
161 
162