1 // Copyright (C) 2007 Mark Pustjens <pustjens@dds.nl>
2 // Copyright (C) 2010-2015 Petr Pavlu <setup@dagobah.cz>
4 // This file is part of CenterIM.
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/>.
20 /// General classes, functions and enumerations.
22 /// @ingroup cppconsui
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)
44 #define CPPCONSUI_GNUC_ATTRIBUTE(x) __attribute__(x)
46 #define CPPCONSUI_GNUC_ATTRIBUTE(x)
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
,
65 ERROR_CURSES_COLOR_LIMIT
,
66 ERROR_CURSES_COLOR_INIT
,
75 explicit Error(ErrorCode code
= ERROR_NONE
, const char *string
= nullptr);
76 Error(const Error
&other
);
77 Error
&operator=(const Error
&other
);
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_
; }
93 ErrorCode error_code_
;
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
; }
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
; }
123 struct Rect
: public Point
, public Size
{
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();
145 ColorScheme
*getColorSchemeInstance();
146 CoreManager
*getCoreManagerInstance();
147 KeyConfig
*getKeyConfigInstance();
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
);
164 } // namespace CppConsUI
166 #endif // CPPCONSUI_H
168 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: