Update list of wide characters
[centerim5.git] / cppconsui / CppConsUI.h
blobc30992db18edb9e0f3ae9114157acf4b3474e891
1 // Copyright (C) 2007 Mark Pustjens <pustjens@dds.nl>
2 // Copyright (C) 2010-2015 Petr Pavlu <setup@dagobah.cz>
3 //
4 // This file is part of CenterIM.
5 //
6 // CenterIM is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // CenterIM is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with CenterIM. If not, see <http://www.gnu.org/licenses/>.
19 /// @file
20 /// General classes, functions and enumerations.
21 ///
22 /// @ingroup cppconsui
24 #ifndef CPPCONSUI_H
25 #define CPPCONSUI_H
27 #include <cinttypes>
28 #include <climits>
29 #include <cstdint>
30 #include <cstdlib>
31 #include <sigc++/sigc++.h>
33 #define COLORSCHEME (CppConsUI::getColorSchemeInstance())
34 #define COREMANAGER (CppConsUI::getCoreManagerInstance())
35 #define KEYCONFIG (CppConsUI::getKeyConfigInstance())
37 #define CONSUI_DISABLE_COPY(Class) \
38 Class(const Class &); \
39 Class &operator=(const Class &)
41 #define PRINTF_WIDTH(type) ((CHAR_BIT * sizeof(type) + 2) / 3 + 1)
43 #ifdef __GNUC__
44 #define CPPCONSUI_GNUC_ATTRIBUTE(x) __attribute__(x)
45 #else
46 #define CPPCONSUI_GNUC_ATTRIBUTE(x)
47 #endif
49 namespace CppConsUI {
51 enum ErrorCode {
52 ERROR_NONE,
54 ERROR_LIBTERMKEY_INITIALIZATION,
55 ERROR_ICONV_INITIALIZATION,
56 ERROR_SCREEN_RESIZING_INITIALIZATION,
57 ERROR_SCREEN_RESIZING_FINALIZATION,
59 ERROR_INPUT_CONVERSION,
61 ERROR_CURSES_INITIALIZATION,
62 ERROR_CURSES_FINALIZATION,
63 ERROR_CURSES_ADD_CHARACTER,
64 ERROR_CURSES_ATTR,
65 ERROR_CURSES_COLOR_LIMIT,
66 ERROR_CURSES_COLOR_INIT,
67 ERROR_CURSES_CLEAR,
68 ERROR_CURSES_REFRESH,
69 ERROR_CURSES_BEEP,
70 ERROR_CURSES_RESIZE,
73 class Error {
74 public:
75 explicit Error(ErrorCode code = ERROR_NONE, const char *string = nullptr);
76 Error(const Error &other);
77 Error &operator=(const Error &other);
78 virtual ~Error();
80 bool present() const { return error_code_ != ERROR_NONE; }
82 void setCode(ErrorCode code);
83 ErrorCode getCode() const { return error_code_; }
85 void setString(const char *string);
86 void setFormattedString(const char *format, ...)
87 CPPCONSUI_GNUC_ATTRIBUTE((format(printf, 2, 3)));
88 const char *getString() const { return error_string_; }
90 void clear();
92 protected:
93 ErrorCode error_code_;
94 char *error_string_;
97 enum WrapMode {
98 WRAP_NONE,
99 WRAP_CHAR,
100 WRAP_WORD,
103 struct Point {
104 Point() : x(0), y(0) {}
105 Point(int x, int y) : x(x), y(y) {}
107 int getX() const { return x; }
108 int getY() const { return y; }
110 int x, y;
113 struct Size {
114 Size() : width(0), height(0) {}
115 Size(int w, int h) : width(w), height(h) {}
117 int getWidth() const { return width; }
118 int getHeight() const { return height; }
120 int width, height;
123 struct Rect : public Point, public Size {
124 Rect() {}
125 Rect(int x, int y, int w, int h) : Point(x, y), Size(w, h) {}
127 int getLeft() const { return x; }
128 int getTop() const { return y; }
129 int getRight() const { return x + width - 1; }
130 int getBottom() const { return y + height - 1; }
133 struct AppInterface {
134 sigc::slot<void> redraw;
135 sigc::slot<void, const char *> logDebug;
138 void initializeConsUI(AppInterface &interface);
139 void finalizeConsUI();
141 class ColorScheme;
142 class CoreManager;
143 class KeyConfig;
145 ColorScheme *getColorSchemeInstance();
146 CoreManager *getCoreManagerInstance();
147 KeyConfig *getKeyConfigInstance();
149 namespace UTF8 {
151 typedef std::uint32_t UniChar;
152 #define UNICHAR_FORMAT PRIu32
153 UniChar getUniChar(const char *p);
154 bool isUniCharWide(UniChar uc);
155 bool isUniCharDigit(UniChar uc);
156 bool isUniCharSpace(UniChar uc);
157 const char *getNextChar(const char *p);
158 const char *getPrevChar(const char *p);
159 const char *findNextChar(const char *p, const char *end);
160 const char *findPrevChar(const char *start, const char *p);
162 } // namespace UTF8
164 } // namespace CppConsUI
166 #endif // CPPCONSUI_H
168 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: