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