]> git.lyx.org Git - features.git/blob - src/frontends/gtk/GWorkArea.h
The EnumLColor patch, free of macros.
[features.git] / src / frontends / gtk / GWorkArea.h
1 // -*- C++ -*-
2 /**
3  * \file GWorkArea.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Huang Ying
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef GWORKAREA_H
13 #define GWORKAREA_H
14
15 #include <gdk/gdkx.h>
16 #include "frontends/WorkArea.h"
17 #include "GPainter.h"
18 #include <gtk/gtk.h>
19 #include <X11/Xft/Xft.h>
20
21 class EnumLColor;
22
23 class ColorCache
24 {
25         typedef std::map<EnumLColor, Gdk::Color *> Map;
26         typedef Map::iterator MapIt;
27         typedef std::map<EnumLColor, XftColor *> Map2;
28         typedef Map2::iterator MapIt2;
29 public:
30         ~ColorCache() { clear(); }
31         Gdk::Color * getColor(EnumLColor clr)
32         {
33                 MapIt it = cache_.find(clr);
34                 return it == cache_.end() ? 0 : it->second;
35         }
36         XftColor * getXftColor(EnumLColor clr)
37         {
38                 MapIt2 it = cache2_.find(clr);
39                 return it == cache2_.end() ? 0 : it->second;
40         }
41         void cacheColor(EnumLColor clr, Gdk::Color * gclr)
42         {
43                 cache_[clr] = gclr;
44         }
45         void cacheXftColor(EnumLColor clr, XftColor * xclr)
46         {
47                 cache2_[clr] = xclr;
48         }
49         void clear();
50 private:
51         Map cache_;
52         Map2 cache2_;
53 };
54
55 extern ColorCache colorCache;
56
57 class ColorHandler
58 {
59 public:
60         ColorHandler(GWorkArea& owner) : owner_(owner) {}
61         XftColor * getXftColor(EnumLColor clr);
62         Gdk::Color * getGdkColor(EnumLColor clr);
63 private:
64         GWorkArea & owner_;
65 };
66
67 class GWorkArea : public WorkArea, public SigC::Object
68 {
69 public:
70         GWorkArea(int width, int height);
71         ~GWorkArea();
72
73         virtual Painter & getPainter() { return painter_; }
74         ///
75         virtual int workWidth() const { return workArea_.get_width(); }
76         ///
77         virtual int workHeight() const { return workArea_.get_height(); }
78         /// return x position of window
79         int xpos() const { return 0; }
80         /// return y position of window
81         int ypos() const { return 0; }
82         ///
83         Glib::RefPtr<Gdk::Window> getWindow() { return workArea_.get_window(); }
84         Display * getDisplay() const
85         { return GDK_WINDOW_XDISPLAY(
86                 const_cast<GdkWindow*>(workArea_.get_window()->gobj())); }
87         Glib::RefPtr<Gdk::Pixmap> getPixmap() { return workAreaPixmap_; }
88         Glib::RefPtr<Gdk::GC> getGC() { return workAreaGC_; }
89         Glib::RefPtr<Gdk::Colormap> getColormap()
90         { return workArea_.get_colormap(); }
91         XftDraw * getXftDraw() { return draw_; }
92         ColorHandler & getColorHandler() { return colorHandler_; }
93
94         virtual void setScrollbarParams(int height, int pos, int line_height);
95         /// a selection exists
96         virtual void haveSelection(bool) const;
97         ///
98         virtual string const getClipboard() const;
99         ///
100         virtual void putClipboard(string const &) const;
101         void inputCommit(gchar * str);
102 private:
103         bool onExpose(GdkEventExpose * event);
104         bool onConfigure(GdkEventConfigure * event);
105         void onScroll();
106         bool onButtonPress(GdkEventButton * event);
107         bool onButtonRelease(GdkEventButton * event);
108         bool onMotionNotify(GdkEventMotion * event);
109         bool onKeyPress(GdkEventKey * event);
110         void onClipboardGet(Gtk::SelectionData& selection_data, guint info);
111         void onClipboardClear();
112         Gtk::HBox hbox_;
113         Gtk::DrawingArea workArea_;
114         Gtk::VScrollbar vscrollbar_;
115         /// The pixmap overlay on the workarea
116         Glib::RefPtr<Gdk::Pixmap> workAreaPixmap_;
117         Glib::RefPtr<Gdk::GC> workAreaGC_;
118         /// the xforms-specific painter
119         GPainter painter_;
120         XftDraw * draw_;
121         ColorHandler colorHandler_;
122         GtkIMContext * imContext_;
123         string inputCache_;
124 };
125
126 #endif