]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GWorkArea.h
Pass LyxView & to the WorkArea.
[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 class ColorCache
27 {
28         typedef std::map<LColor_color, Gdk::Color *> Map;
29         typedef Map::iterator MapIt;
30         typedef std::map<LColor_color, XftColor *> Map2;
31         typedef Map2::iterator MapIt2;
32 public:
33         ~ColorCache();
34         Gdk::Color * getColor(LColor_color);
35         XftColor * getXftColor(LColor_color);
36         void cacheColor(LColor_color, Gdk::Color *);
37         void cacheXftColor(LColor_color, XftColor *);
38         void clear();
39 private:
40         Map cache_;
41         Map2 cache2_;
42 };
43
44 extern ColorCache colorCache;
45
46 class ColorHandler
47 {
48 public:
49         ColorHandler(GWorkArea& owner) : owner_(owner) {}
50         XftColor * getXftColor(LColor_color clr);
51         Gdk::Color * getGdkColor(LColor_color clr);
52 private:
53         GWorkArea & owner_;
54 };
55
56
57 class GWorkArea : public WorkArea, public SigC::Object
58 {
59 public:
60         GWorkArea(LyXView & owner, int width, int height);
61         ~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) const;
84         ///
85         virtual std::string const getClipboard() const;
86         ///
87         virtual void putClipboard(std::string const &) const;
88         void inputCommit(gchar * str);
89 private:
90         bool onExpose(GdkEventExpose * event);
91         bool onConfigure(GdkEventConfigure * event);
92         void onScroll();
93         bool onButtonPress(GdkEventButton * event);
94         bool onButtonRelease(GdkEventButton * event);
95         bool onMotionNotify(GdkEventMotion * event);
96         bool onKeyPress(GdkEventKey * event);
97         void onClipboardGet(Gtk::SelectionData& selection_data, guint info);
98         void onClipboardClear();
99         Gtk::HBox hbox_;
100         Gtk::DrawingArea workArea_;
101         Gtk::VScrollbar vscrollbar_;
102         /// The pixmap overlay on the workarea
103         Glib::RefPtr<Gdk::Pixmap> workAreaPixmap_;
104         Glib::RefPtr<Gdk::GC> workAreaGC_;
105         /// the xforms-specific painter
106         GPainter painter_;
107         XftDraw * draw_;
108         ColorHandler colorHandler_;
109         GtkIMContext * imContext_;
110         std::string inputCache_;
111 };
112
113 #endif