1 // Copyright (C) 2008 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 /// ColorScheme class.
22 /// @ingroup cppconsui
27 #include "ConsUICurses.h"
28 #include "CppConsUI.h" // for COLORSCHEME macro
33 // Uncomment to enable an experimental feature to lower the number of used
35 //#define SAVE_COLOR_PAIRS
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
{
55 CONVERSION_ERROR_WIDGET
,
56 CONVERSION_ERROR_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
,
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
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
);
88 int getColorPair(const Color
&c
, int *attrs
, Error
&error
);
91 /// Sets color pair and Curses attributes for a given scheme, widget, property
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_
; }
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
);
110 typedef std::pair
<int, int> ColorPair
;
111 typedef std::map
<ColorPair
, int> ColorPairs
;
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: