14 #ifndef T3_WIDGET_UTIL_H
15 #define T3_WIDGET_UTIL_H
19 #include <sigc++/sigc++.h>
20 #include <t3window/window.h>
22 #include <t3widget/widget_api.h>
23 #include <t3widget/ptr.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; }
52 bool operator==(
const text_coordinate_t &other)
const {
return line == other.line && pos == other.pos; }
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 || (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); }
62 #define T3_WIDGET_SIGNAL(_name, ...) \
64 sigc::signal<__VA_ARGS__> _name; \
66 sigc::connection connect_##_name(const sigc::slot<__VA_ARGS__> &_slot) { return _name.connect(_slot); }
68 #define _T3_WIDGET_ENUM(_name, ...) \
69 class T3_WIDGET_API _name { \
75 _name(_values _value_arg) : _value(_value_arg) {} \
76 _values operator =(_values _value_arg) { _value = _value_arg; return _value; } \
77 operator int (void) const { return (int) _value; } \
78 bool operator == (_values _value_arg) const { return _value == _value_arg; } \
83 _T3_WIDGET_ENUM(selection_mode_t,
90 _T3_WIDGET_ENUM(find_flags_t,
95 TRANSFROM_BACKSLASH = (1<<4),
96 WHOLE_WORD = (1<<5) | (1<<6),
97 ANCHOR_WORD_LEFT = (1<<5),
98 ANCHOR_WORD_RIGHT = (1<<6),
100 REPLACEMENT_VALID = (1<<8),
103 _T3_WIDGET_ENUM(find_action_t,
112 _T3_WIDGET_ENUM(attribute_t,
114 TEXT_SELECTION_CURSOR,
115 TEXT_SELECTION_CURSOR2,
141 _T3_WIDGET_ENUM(rewrap_type_t,
149 _T3_WIDGET_ENUM(wrap_type_t,
155 #undef _T3_WIDGET_ENUM
158 typedef cleanup_func_ptr<t3_window_t, t3_win_del>::t cleanup_t3_window_ptr;
161 T3_WIDGET_API ssize_t nosig_write(
int fd,
const char *buffer,
size_t bytes);
162 T3_WIDGET_API ssize_t nosig_read(
int fd,
char *buffer,
size_t bytes);
164 T3_WIDGET_API std::string get_working_directory(
void);
165 T3_WIDGET_API std::string get_directory(
const char *directory);
166 T3_WIDGET_API
bool is_dir(
const std::string *current_dir,
const char *name);
168 T3_WIDGET_API
void convert_lang_codeset(
const char *str,
size_t len, std::string *result,
bool from);
169 T3_WIDGET_API
void convert_lang_codeset(
const char *str, std::string *result,
bool from);
170 T3_WIDGET_API
void convert_lang_codeset(
const std::string *str, std::string *result,
bool from);