]> git.lyx.org Git - lyx.git/blob - src/ColorHandler.h
fix to #241 and #300 from John
[lyx.git] / src / ColorHandler.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  *
5  *           LyX, The Document Processor
6  *
7  *          Copyright 1995-2001 The LyX Team
8  *
9  * ======================================================*/
10
11 #ifndef COLOR_HANDLER_H
12 #define COLOR_HANDLER_H
13
14 #ifdef __GNUG__
15 #pragma interface
16 #endif
17
18 #include <boost/smart_ptr.hpp>
19
20 // This is only included to provide stuff for the non-public sections
21 #include <X11/Xlib.h>
22
23 #include "PainterBase.h"
24
25 class LyXFont;
26
27 /**
28  * This is a factory class that can produce GCs with a specific
29  * color. It will cache GCs for performance.
30  */
31 class LyXColorHandler {
32 public:
33         ///
34         LyXColorHandler();
35         ///
36         ~LyXColorHandler();
37         ///
38         unsigned long colorPixel(LColor::color c);
39         ///
40         GC getGCForeground(LColor::color c);
41         ///
42         GC getGCLinepars(PainterBase::line_style,
43                          PainterBase::line_width, LColor::color c);
44         /// update the cache after a color definition change
45         void updateColor(LColor::color c);
46
47 private:
48         ///
49         Display * display;
50         ///
51         Colormap colormap;
52         ///
53         GC colorGCcache[LColor::ignore + 1];
54         ///
55         typedef std::map<int, GC> LineGCCache;
56         ///
57         LineGCCache lineGCcache;
58         ///
59         Pixmap drawable;
60 };
61
62 ///
63 extern boost::scoped_ptr<LyXColorHandler> lyxColorHandler;
64
65 #endif