Update list of wide characters
[centerim5.git] / cppconsui / ColorScheme.h
blobd73df50982106bea360259cb155cd148ff60a9cf
1 // Copyright (C) 2008 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 /// ColorScheme class.
21 ///
22 /// @ingroup cppconsui
24 #ifndef COLORSCHEME_H
25 #define COLORSCHEME_H
27 #include "ConsUICurses.h"
28 #include "CppConsUI.h" // for COLORSCHEME macro
30 #include <map>
31 #include <string>
33 // Uncomment to enable an experimental feature to lower the number of used
34 // colorpairs.
35 //#define SAVE_COLOR_PAIRS
37 namespace CppConsUI {
39 class ColorScheme {
40 public:
41 struct Color {
42 int foreground;
43 int background;
44 int attrs;
46 Color(int f = Curses::Color::DEFAULT, int b = Curses::Color::DEFAULT,
47 int a = Curses::Attr::NORMAL)
48 : foreground(f), background(b), attrs(a)
53 enum PropertyConversionResult {
54 CONVERSION_SUCCESS,
55 CONVERSION_ERROR_WIDGET,
56 CONVERSION_ERROR_PROPERTY,
59 enum Property {
60 PROPERTY_BUTTON_FOCUS,
61 PROPERTY_BUTTON_NORMAL,
62 PROPERTY_CHECKBOX_FOCUS,
63 PROPERTY_CHECKBOX_NORMAL,
64 PROPERTY_CONTAINER_BACKGROUND,
65 PROPERTY_HORIZONTALLINE_LINE,
66 PROPERTY_LABEL_TEXT,
67 PROPERTY_PANEL_LINE,
68 PROPERTY_PANEL_TITLE,
69 PROPERTY_TEXTEDIT_TEXT,
70 PROPERTY_TEXTVIEW_TEXT,
71 PROPERTY_TEXTVIEW_SCROLLBAR,
72 PROPERTY_VERTICALLINE_LINE,
73 PROPERTY_TREEVIEW_LINE,
76 typedef std::pair<int, int> PropertyPair;
77 typedef std::map<PropertyPair, Color> Properties;
78 typedef std::map<int, Properties> Schemes;
80 /// Gets color pair and Curses attributes (that can be passed to
81 /// Curses::ViewPort::attrOn()) for a given scheme, widget and property
82 /// combination.
83 int getAttributes(
84 int scheme, int property, int subproperty, int *out_attrs, Error &error);
85 #ifdef SAVE_COLOR_PAIRS
86 int getColorPair(Color &c, int *attrs, Error &error);
87 #else
88 int getColorPair(const Color &c, int *attrs, Error &error);
89 #endif
91 /// Sets color pair and Curses attributes for a given scheme, widget, property
92 /// combination.
93 bool setAttributes(int scheme, int property, int foreground, int background,
94 int attrs = Curses::Attr::NORMAL, bool overwrite = false);
95 bool setAttributesExt(int scheme, int property, int subproperty,
96 int foreground, int background, int attrs = Curses::Attr::NORMAL,
97 bool overwrite = false);
99 void freeScheme(int scheme);
100 const Schemes &getSchemes() const { return schemes_; }
102 void clear();
104 static const char *propertyToWidgetName(int property);
105 static const char *propertyToPropertyName(int property);
106 static PropertyConversionResult stringPairToPropertyPair(const char *widget,
107 const char *property, int *out_property, int *out_subproperty);
109 private:
110 typedef std::pair<int, int> ColorPair;
111 typedef std::map<ColorPair, int> ColorPairs;
113 Schemes schemes_;
114 ColorPairs pairs_;
116 ColorScheme() {}
117 ~ColorScheme() {}
118 CONSUI_DISABLE_COPY(ColorScheme);
120 friend void initializeConsUI(AppInterface &interface);
121 friend void finalizeConsUI();
124 } // namespace CppConsUI
126 #endif // COLORSCHEME_H
128 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: