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