]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GScreen.C
Wrap most of the frontend code up inside namespace lyx::frontend.
[lyx.git] / src / frontends / gtk / GScreen.C
1 /**
2  * \file GScreen.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Huang Ying
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12 #include <gtkmm.h>
13
14 #include "GScreen.h"
15
16 #include "GWorkArea.h"
17
18 #include "buffer.h"
19 #include "BufferView.h"
20 #include "debug.h"
21 #include "language.h"
22 #include "LColor.h"
23 #include "lyxtext.h"
24 #include "lyxrow.h"
25
26 #include "frontends/screen.h"
27 #include "frontends/font_metrics.h"
28 #include "frontends/Painter.h"
29 #include "frontends/WorkArea.h"
30
31 #include "insets/insettext.h"
32
33 #include <algorithm>
34
35 namespace lyx {
36 namespace frontend {
37
38 GScreen::GScreen(GWorkArea & o)
39         : LyXScreen(), owner_(o)
40 {
41         // the cursor isnt yet visible
42         cursorX_ = 0;
43         cursorY_ = 0;
44         cursorW_ = 0;
45         cursorH_ = 0;
46 }
47
48
49 GScreen::~GScreen()
50 {
51 }
52
53
54 WorkArea & GScreen::workarea() const
55 {
56         return owner_;
57 }
58
59
60 void GScreen::setCursorColor(Glib::RefPtr<Gdk::GC> gc)
61 {
62         Gdk::Color * clr = owner_.getColorHandler().
63                 getGdkColor(LColor::cursor);
64         gc->set_foreground(*clr);
65 }
66
67
68 void GScreen::showCursor(int x, int y,
69                          int h, Cursor_Shape shape)
70 {
71         // Update the cursor color.
72         setCursorColor(owner_.getGC());
73
74         cursorX_ = x;
75         cursorY_ = y;
76         cursorH_ = h;
77
78         switch (shape) {
79         case BAR_SHAPE:
80                 cursorW_ = 1;
81                 break;
82         case L_SHAPE:
83                 cursorW_ = cursorH_ / 3;
84                 break;
85         case REVERSED_L_SHAPE:
86                 cursorW_ = cursorH_ / 3;
87                 cursorX_ = x - cursorW_ + 1;
88                 break;
89         }
90
91         int fx, fy, fwidth, fheight, fdepth;
92         owner_.getWindow()->get_geometry(fx, fy, fwidth, fheight, fdepth);
93         cursorPixmap_ = Gdk::Pixmap::create(owner_.getWindow(),
94                                             cursorW_,
95                                             cursorH_,
96                                             fdepth);
97         cursorPixmap_->draw_drawable(owner_.getGC(),
98                                      owner_.getWindow(),
99                                      owner_.xpos() + cursorX_,
100                                      owner_.ypos() + cursorY_,
101                                      0, 0,
102                                      cursorW_,
103                                      cursorH_);
104         owner_.getWindow()->draw_line(owner_.getGC(),
105                                       x + owner_.xpos(),
106                                       y + owner_.ypos(),
107                                       x + owner_.xpos(),
108                                       y + h - 1 + owner_.ypos());
109         switch (shape) {
110         case BAR_SHAPE:
111                 break;
112         case L_SHAPE:
113         case REVERSED_L_SHAPE:
114                 owner_.getWindow()->draw_line(owner_.getGC(),
115                                               owner_.xpos() + cursorX_,
116                                               owner_.ypos() + y + h - 1,
117                                               owner_.xpos() + cursorX_ + cursorW_ - 1,
118                                               owner_.xpos() + y + h - 1);
119                 break;
120         }
121 }
122
123
124 void GScreen::removeCursor()
125 {
126         if (cursorPixmap_) {
127                 owner_.getWindow()->draw_drawable(owner_.getGC(),
128                                                   cursorPixmap_,
129                                                   0, 0,
130                                                   cursorX_ + owner_.xpos(),
131                                                   cursorY_ + owner_.ypos(),
132                                                   cursorW_, cursorH_);
133         }
134 }
135
136
137 void GScreen::expose(int x, int y, int w, int h)
138 {
139         lyxerr[Debug::GUI] << "expose " << w << 'x' << h
140                 << '+' << x << '+' << y << std::endl;
141         owner_.getWindow()->draw_drawable(owner_.getGC(),
142                                           owner_.getPixmap(),
143                                           x, y,
144                                           x + owner_.xpos(),
145                                           y + owner_.ypos(),
146                                           w, h);
147 }
148
149 } // namespace frontend
150 } // namespace lyx