]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GScreen.C
Extracted from r14281
[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
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
16 #endif
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
19 #endif
20
21 #include "GScreen.h"
22
23 #include "GWorkArea.h"
24
25 #include "buffer.h"
26 #include "BufferView.h"
27 #include "debug.h"
28 #include "language.h"
29 #include "LColor.h"
30 #include "lyxtext.h"
31 #include "lyxrow.h"
32
33 #include "frontends/font_metrics.h"
34 #include "frontends/Painter.h"
35 #include "frontends/GuiCursor.h"
36
37 #include "insets/insettext.h"
38
39 #include <algorithm>
40
41 namespace lyx {
42 namespace frontend {
43
44 GScreen::GScreen(GWorkArea & o)
45         : owner_(o)
46 {
47         // the cursor isnt yet visible
48         cursorX_ = 0;
49         cursorY_ = 0;
50         cursorW_ = 0;
51         cursorH_ = 0;
52 }
53
54
55 GScreen::~GScreen()
56 {
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, int h, CursorShape shape)
69 {
70         // Update the cursor color.
71         setCursorColor(owner_.getGC());
72
73         cursorX_ = x;
74         cursorY_ = y;
75         cursorH_ = h;
76
77         switch (shape) {
78         case BAR_SHAPE:
79                 cursorW_ = 1;
80                 break;
81         case L_SHAPE:
82                 cursorW_ = cursorH_ / 3;
83                 break;
84         case REVERSED_L_SHAPE:
85                 cursorW_ = cursorH_ / 3;
86                 cursorX_ = x - cursorW_ + 1;
87                 break;
88         }
89
90         int fx, fy, fwidth, fheight, fdepth;
91         owner_.getWindow()->get_geometry(fx, fy, fwidth, fheight, fdepth);
92         cursorPixmap_ = Gdk::Pixmap::create(owner_.getWindow(),
93                                             cursorW_,
94                                             cursorH_,
95                                             fdepth);
96         cursorPixmap_->draw_drawable(owner_.getGC(),
97                                      owner_.getWindow(),
98                                      owner_.xpos() + cursorX_,
99                                      owner_.ypos() + cursorY_,
100                                      0, 0,
101                                      cursorW_,
102                                      cursorH_);
103         owner_.getWindow()->draw_line(owner_.getGC(),
104                                       x + owner_.xpos(),
105                                       y + owner_.ypos(),
106                                       x + owner_.xpos(),
107                                       y + h - 1 + owner_.ypos());
108         switch (shape) {
109         case BAR_SHAPE:
110                 break;
111         case L_SHAPE:
112         case REVERSED_L_SHAPE:
113                 owner_.getWindow()->draw_line(owner_.getGC(),
114                                               owner_.xpos() + cursorX_,
115                                               owner_.ypos() + y + h - 1,
116                                               owner_.xpos() + cursorX_ + cursorW_ - 1,
117                                               owner_.xpos() + y + h - 1);
118                 break;
119         }
120 }
121
122
123 void GScreen::removeCursor()
124 {
125         if (cursorPixmap_) {
126                 owner_.getWindow()->draw_drawable(owner_.getGC(),
127                                                   cursorPixmap_,
128                                                   0, 0,
129                                                   cursorX_ + owner_.xpos(),
130                                                   cursorY_ + owner_.ypos(),
131                                                   cursorW_, cursorH_);
132         }
133 }
134
135
136 void GScreen::expose(int x, int y, int w, int h)
137 {
138         lyxerr[Debug::GUI] << "expose " << w << 'x' << h
139                 << '+' << x << '+' << y << std::endl;
140         owner_.getWindow()->draw_drawable(owner_.getGC(),
141                                           owner_.getPixmap(),
142                                           x, y,
143                                           x + owner_.xpos(),
144                                           y + owner_.ypos(),
145                                           w, h);
146 }
147
148 } // namespace frontend
149 } // namespace lyx