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