]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GScreen.C
more compile fixes
[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/Painter.h"
34
35 #include "insets/insettext.h"
36
37 #include <algorithm>
38
39 // FIXME: defined in X.h, spuriously pulled in by some gui headers
40 #undef CursorShape
41
42 namespace lyx {
43 namespace frontend {
44
45         //using lyx::frontend::CursorShape;
46
47 GScreen::GScreen(GWorkArea & o)
48         : owner_(o)
49 {
50         // the cursor isnt yet visible
51         cursorX_ = 0;
52         cursorY_ = 0;
53         cursorW_ = 0;
54         cursorH_ = 0;
55 }
56
57
58 GScreen::~GScreen()
59 {
60 }
61
62
63 void GScreen::setCursorColor(Glib::RefPtr<Gdk::GC> gc)
64 {
65         Gdk::Color * clr = owner_.getColorHandler().
66                 getGdkColor(LColor::cursor);
67         gc->set_foreground(*clr);
68 }
69
70
71 void GScreen::showCursor(int x, int y, int h, CursorShape shape)
72 {
73         // Update the cursor color.
74         setCursorColor(owner_.getGC());
75
76         cursorX_ = x;
77         cursorY_ = y;
78         cursorH_ = h;
79
80         switch (shape) {
81         case BAR_SHAPE:
82                 cursorW_ = 1;
83                 break;
84         case L_SHAPE:
85                 cursorW_ = cursorH_ / 3;
86                 break;
87         case REVERSED_L_SHAPE:
88                 cursorW_ = cursorH_ / 3;
89                 cursorX_ = x - cursorW_ + 1;
90                 break;
91         }
92
93         int fx, fy, fwidth, fheight, fdepth;
94         owner_.getWindow()->get_geometry(fx, fy, fwidth, fheight, fdepth);
95         cursorPixmap_ = Gdk::Pixmap::create(owner_.getWindow(),
96                                             cursorW_,
97                                             cursorH_,
98                                             fdepth);
99         cursorPixmap_->draw_drawable(owner_.getGC(),
100                                      owner_.getWindow(),
101                                      owner_.xpos() + cursorX_,
102                                      owner_.ypos() + cursorY_,
103                                      0, 0,
104                                      cursorW_,
105                                      cursorH_);
106         owner_.getWindow()->draw_line(owner_.getGC(),
107                                       x + owner_.xpos(),
108                                       y + owner_.ypos(),
109                                       x + owner_.xpos(),
110                                       y + h - 1 + owner_.ypos());
111         switch (shape) {
112         case BAR_SHAPE:
113                 break;
114         case L_SHAPE:
115         case REVERSED_L_SHAPE:
116                 owner_.getWindow()->draw_line(owner_.getGC(),
117                                               owner_.xpos() + cursorX_,
118                                               owner_.ypos() + y + h - 1,
119                                               owner_.xpos() + cursorX_ + cursorW_ - 1,
120                                               owner_.xpos() + y + h - 1);
121                 break;
122         }
123 }
124
125
126 void GScreen::removeCursor()
127 {
128         if (cursorPixmap_) {
129                 owner_.getWindow()->draw_drawable(owner_.getGC(),
130                                                   cursorPixmap_,
131                                                   0, 0,
132                                                   cursorX_ + owner_.xpos(),
133                                                   cursorY_ + owner_.ypos(),
134                                                   cursorW_, cursorH_);
135         }
136 }
137
138
139 void GScreen::expose(int x, int y, int w, int h)
140 {
141         lyxerr[Debug::GUI] << "expose " << w << 'x' << h
142                 << '+' << x << '+' << y << std::endl;
143         owner_.getWindow()->draw_drawable(owner_.getGC(),
144                                           owner_.getPixmap(),
145                                           x, y,
146                                           x + owner_.xpos(),
147                                           y + owner_.ypos(),
148                                           w, h);
149 }
150
151 } // namespace frontend
152 } // namespace lyx