14 #ifndef T3_WIDGET_UTIL_H 15 #define T3_WIDGET_UTIL_H 19 #include <t3window/window.h> 21 #include <t3widget/widget_api.h> 22 #include <t3widget/ptr.h> 23 #include <t3widget/signals.h> 35 optional(
void) : initialized(
false) {}
36 optional(T _value) : value(_value), initialized(
true) {}
37 bool is_valid(
void)
const {
return initialized; }
38 void unset(
void) { initialized =
false; }
39 operator T (
void)
const {
if (!initialized)
throw(0);
return (T) value; }
40 T operator()(
void)
const {
if (!initialized)
throw(0);
return (T) value; }
41 optional & operator=(
const optional &other) { initialized = other.initialized; value = other.value;
return *
this; }
42 optional & operator=(
const T other) { initialized =
true; value = other;
return *
this; }
43 T value_or_default(T dflt) {
return initialized ? value : dflt; }
48 T3_WIDGET_API
extern const optint
None;
53 bool operator==(
const text_coordinate_t &other)
const {
return line == other.line && pos == other.pos; }
54 bool operator!=(
const text_coordinate_t &other)
const {
return line != other.line || pos != other.pos; }
55 bool operator>(
const text_coordinate_t &other)
const {
return line > other.line || (line == other.line && pos > other.pos); }
56 bool operator>=(
const text_coordinate_t &other)
const {
return line > other.line || (line == other.line && pos >= other.pos); }
57 bool operator<(
const text_coordinate_t &other)
const {
return line < other.line || (line == other.line && pos < other.pos); }
58 bool operator<=(
const text_coordinate_t &other)
const {
return line < other.line || (line == other.line && pos <= other.pos); }
63 #define T3_WIDGET_SIGNAL(_name, ...) \ 65 signals::signal<__VA_ARGS__> _name; \ 67 signals::connection connect_##_name(const signals::slot<__VA_ARGS__> &_slot) { return _name.connect(_slot); } 69 #define _T3_WIDGET_ENUM(_name, ...) \ 70 class T3_WIDGET_API _name { \ 76 _name(_values _value_arg) : _value(_value_arg) {} \ 77 _values operator =(_values _value_arg) { _value = _value_arg; return _value; } \ 78 operator int (void) const { return (int) _value; } \ 79 bool operator == (_values _value_arg) const { return _value == _value_arg; } \ 84 _T3_WIDGET_ENUM(selection_mode_t,
91 _T3_WIDGET_ENUM(find_flags_t,
96 TRANSFROM_BACKSLASH = (1<<4),
97 WHOLE_WORD = (1<<5) | (1<<6),
98 ANCHOR_WORD_LEFT = (1<<5),
99 ANCHOR_WORD_RIGHT = (1<<6),
101 REPLACEMENT_VALID = (1<<8),
104 _T3_WIDGET_ENUM(find_action_t,
113 _T3_WIDGET_ENUM(attribute_t,
115 TEXT_SELECTION_CURSOR,
116 TEXT_SELECTION_CURSOR2,
142 _T3_WIDGET_ENUM(rewrap_type_t,
150 _T3_WIDGET_ENUM(wrap_type_t,
156 #undef _T3_WIDGET_ENUM 159 typedef cleanup_func_ptr<t3_window_t, t3_win_del>::t cleanup_t3_window_ptr;
162 T3_WIDGET_API ssize_t nosig_write(
int fd,
const char *buffer,
size_t bytes);
163 T3_WIDGET_API ssize_t nosig_read(
int fd,
char *buffer,
size_t bytes);
165 T3_WIDGET_API std::string get_working_directory(
void);
166 T3_WIDGET_API std::string get_directory(
const char *directory);
167 T3_WIDGET_API
void sanitize_dir(std::string *directory);
168 T3_WIDGET_API
bool is_dir(
const std::string *current_dir,
const char *name);
170 T3_WIDGET_API
void convert_lang_codeset(
const char *str,
size_t len, std::string *result,
bool from);
171 T3_WIDGET_API
void convert_lang_codeset(
const char *str, std::string *result,
bool from);
172 T3_WIDGET_API
void convert_lang_codeset(
const std::string *str, std::string *result,
bool from);