libt3widget
internal.h
1 /* Copyright (C) 2011-2012 G.P. Halkes
2  This program is free software: you can redistribute it and/or modify
3  it under the terms of the GNU General Public License version 3, as
4  published by the Free Software Foundation.
5 
6  This program is distributed in the hope that it will be useful,
7  but WITHOUT ANY WARRANTY; without even the implied warranty of
8  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  GNU General Public License for more details.
10 
11  You should have received a copy of the GNU General Public License
12  along with this program. If not, see <http://www.gnu.org/licenses/>.
13 */
14 #ifndef T3_WIDGET_INTERNAL_H
15 #define T3_WIDGET_INTERNAL_H
16 
17 #ifndef _T3_WIDGET_INTERNAL
18 #error This header file is for internal use _only_!!
19 #endif
20 
21 #include <string>
22 #include <t3widget/key.h>
23 
24 #ifdef HAS_SELECT_H
25 #include <sys/select.h>
26 #else
27 #include <sys/time.h>
28 #include <sys/types.h>
29 #include <unistd.h>
30 #endif
31 
32 #include "widget_api.h"
33 #include "main.h"
34 #include "log.h"
35 #include "signals.h"
36 
37 #ifdef HAS_STRDUP
38 #define _t3_widget_strdup strdup
39 #else
40 T3_WIDGET_LOCAL char *_t3_widget_strdup(const char *str);
41 #endif
42 
43 namespace t3_widget {
44 
45 T3_WIDGET_LOCAL extern init_parameters_t *init_params;
46 
47 T3_WIDGET_LOCAL void stop_clipboard(void);
48 
49 #ifdef _T3_WIDGET_DEBUG
50 #define ASSERT(_x) do { if (!(_x)) { \
51  fprintf(stderr, "%s:%d: libt3widget: Assertion failed: %s\n", __FILE__, __LINE__, #_x); abort(); \
52 }} while (0)
53 #else
54 #define ASSERT(_x)
55 #endif
56 
58 #define ESCAPE_UNICODE (1<<29)
59 
60 #define ESCAPE_REPLACEMENT (1<<30)
61 
62 //FIXME: do proper gettext stuff instead of this temporary wrapper
63 #define _(_x) _x
64 
71 T3_WIDGET_LOCAL int parse_escape(const std::string &str, const char **error_message, size_t &read_position,
72  bool replacements = false);
78 T3_WIDGET_LOCAL bool parse_escapes(std::string &str, const char **error_message, bool replacements = false);
79 
80 /* Key handling routines. */
81 class complex_error_t;
83 T3_WIDGET_LOCAL complex_error_t init_keys(const char *term, bool separate_keypad);
85 T3_WIDGET_LOCAL void cleanup_keys(void);
87 T3_WIDGET_LOCAL void deinit_keys(void);
89 T3_WIDGET_LOCAL void reinit_keys(void);
91 T3_WIDGET_LOCAL void insert_protected_key(t3_widget::key_t key);
93 T3_WIDGET_LOCAL bool read_keychar(int timeout);
94 
95 /* char_buffer for key and mouse handling. Has to be shared between key.cc and
96  mouse.cc because of XTerm in-band mouse reporting. */
97 extern char char_buffer[32];
98 extern int char_buffer_fill;
99 
101 T3_WIDGET_LOCAL void init_mouse_reporting(bool xterm_mouse);
103 T3_WIDGET_LOCAL void deinit_mouse_reporting(void);
105 T3_WIDGET_LOCAL void reinit_mouse_reporting(void);
107 T3_WIDGET_LOCAL void stop_mouse_reporting(void);
109 T3_WIDGET_LOCAL bool decode_xterm_mouse(void);
111 T3_WIDGET_LOCAL bool use_xterm_mouse_reporting(void);
113 T3_WIDGET_LOCAL void fd_set_mouse_fd(fd_set *readset, int *max_fd);
115 T3_WIDGET_LOCAL bool check_mouse_fd(fd_set *readset);
116 
117 
118 enum {
119  CLASS_WHITESPACE,
120  CLASS_ALNUM,
121  CLASS_GRAPH,
122  CLASS_OTHER
123 };
124 
126 T3_WIDGET_LOCAL int get_class(const std::string *str, int pos);
127 
128 }; // namespace
129 #endif
int parse_escape(const std::string &str, const char **error_message, size_t &read_position, bool replacements=false)
Parse a single escape sequence in a string.
Definition: util.cc:100
The t3_widget namespace is contains all classes, functions and global variables in the libt3widget li...
Definition: autocompleter.cc:18
bool check_mouse_fd(fd_set *readset)
Check the mouse event fd for events, if appropriate bits in readset indicate available data...
Definition: mouse.cc:310
void stop_mouse_reporting(void)
Stop mouse reporting all together before program termination.
Definition: mouse.cc:289
int get_class(const std::string *str, int pos)
Get the character class associated with the character at a specific position in a string...
Definition: util.cc:412
long key_t
Integer type holding a single key symbol.
Definition: key.h:24
void deinit_keys(void)
Switch to the default keypad mode to allow other applications to function.
Definition: key.cc:667
void init_mouse_reporting(bool xterm_mouse)
Initialize the mouse handling code.
Definition: mouse.cc:255
void fd_set_mouse_fd(fd_set *readset, int *max_fd)
Set bit(s) for mouse event fd.
Definition: mouse.cc:298
void reinit_mouse_reporting(void)
Switch back to mouse reporting after using deinit_mouse_reporting.
Definition: mouse.cc:284
void reinit_keys(void)
Switch back to best keypad mode after using deinit_keys.
Definition: key.cc:672
bool parse_escapes(std::string &str, const char **error_message, bool replacements=false)
Convert escapes in a string to associated values.
Definition: util.cc:223
bool read_keychar(int timeout)
Read chars into buffer for processing.
Definition: key.cc:215
void insert_protected_key(t3_widget::key_t key)
Insert a key to the queue, marked to ensure it is not interpreted by any widget except text widgets...
Definition: key.cc:433
bool use_xterm_mouse_reporting(void)
Report whether XTerm mouse reporting is active.
Definition: mouse.cc:46
void cleanup_keys(void)
Clean-up any data allocated for the key handling code.
Definition: key.cc:677
bool decode_xterm_mouse(void)
Decode an xterm mouse event.
Definition: mouse.cc:91
complex_error_t init_keys(const char *term, bool separate_keypad)
Initialize the key handling code.
Definition: key.cc:490
void deinit_mouse_reporting(void)
Switch off mouse reporting to allow other applications to function.
Definition: mouse.cc:279