3 * Copyright 1995-2002 the LyX Team
4 * Read the file COPYING
7 * \author John Levon <moz@compsoc.man.ac.uk>
13 #pragma implementation
19 #include "frontends/screen.h"
20 #include "frontends/font_metrics.h"
21 #include "XWorkArea.h"
28 #include "BufferView.h"
29 #include "insets/insettext.h"
30 #include "ColorHandler.h"
43 val.foreground = BlackPixel(fl_get_display(),
44 DefaultScreen(fl_get_display()));
46 val.function = GXcopy;
47 val.graphics_exposures = false;
48 val.line_style = LineSolid;
50 return XCreateGC(fl_get_display(), RootWindow(fl_get_display(), 0),
51 GCForeground | GCFunction | GCGraphicsExposures
52 | GCLineWidth | GCLineStyle, &val);
59 XScreen::XScreen(XWorkArea & o)
60 : LyXScreen(), owner_(o)
62 // the cursor isnt yet visible
76 XFreeGC(fl_get_display(), gc_copy);
80 void XScreen::setCursorColor()
82 if (!lyxColorHandler.get()) return;
84 GC gc = lyxColorHandler->getGCForeground(LColor::cursor);
87 XGetGCValues(fl_get_display(),
88 gc, GCForeground, &val);
89 XChangeGC(fl_get_display(), gc_copy, GCForeground, &val);
93 void XScreen::showManualCursor(LyXText const * text, int x, int y,
94 int asc, int desc, Cursor_Shape shape)
96 // Update the cursor color.
99 int const y1 = max(y - text->first_y - asc, 0);
100 int const y_tmp = min(y - text->first_y + desc,
101 static_cast<int>(owner_.workHeight()));
103 // Secure against very strange situations
104 int const y2 = max(y_tmp, y1);
107 XFreePixmap(fl_get_display(), cursor_pixmap);
111 if (y2 > 0 && y1 < int(owner_.workHeight())) {
112 cursor_pixmap_h = y2 - y1 + 1;
113 cursor_pixmap_y = y1;
121 cursor_pixmap_w = cursor_pixmap_h/3;
124 case REVERSED_L_SHAPE:
125 cursor_pixmap_w = cursor_pixmap_h/3;
126 cursor_pixmap_x = x - cursor_pixmap_w + 1;
131 XCreatePixmap (fl_get_display(),
135 fl_get_visual_depth());
136 XCopyArea (fl_get_display(),
140 owner_.xpos() + cursor_pixmap_x,
141 owner_.ypos() + cursor_pixmap_y,
145 XDrawLine(fl_get_display(),
156 case REVERSED_L_SHAPE:
157 int const rectangle_h = (cursor_pixmap_h + 10) / 20;
158 XFillRectangle(fl_get_display(),
161 cursor_pixmap_x + owner_.xpos(),
162 y2 - rectangle_h + 1 + owner_.ypos(),
163 cursor_pixmap_w - 1, rectangle_h);
168 cursor_visible_ = true;
172 void XScreen::hideCursor()
174 if (!cursor_visible_) return;
177 XCopyArea (fl_get_display(),
182 cursor_pixmap_w, cursor_pixmap_h,
183 cursor_pixmap_x + owner_.xpos(),
184 cursor_pixmap_y + owner_.ypos());
186 cursor_visible_ = false;
190 void XScreen::expose(int x, int y, int w, int h)
192 lyxerr[Debug::GUI] << "expose " << w << "x" << h
193 << "+" << x << "+" << y << endl;
194 XCopyArea(fl_get_display(),
204 void XScreen::draw(LyXText * text, BufferView * bv, unsigned int y)
206 if (cursor_visible_) hideCursor();
208 int const old_first = text->first_y;
209 bool const internal = (text == bv->text);
212 // is any optimization possible?
213 if ((y - old_first) < owner_.workHeight()
214 && (old_first - y) < owner_.workHeight())
216 if (text->first_y < old_first) {
217 drawFromTo(text, bv, 0,
218 old_first - text->first_y, 0, 0, internal);
219 XCopyArea (fl_get_display(),
226 owner_.workHeight() - old_first + text->first_y,
228 owner_.ypos() + old_first - text->first_y
230 // expose the area drawn
233 old_first - text->first_y);
236 owner_.workHeight() + old_first - text->first_y,
237 owner_.workHeight(), 0, 0, internal);
238 XCopyArea (fl_get_display(),
243 owner_.ypos() + text->first_y - old_first,
245 owner_.workHeight() + old_first - text->first_y,
248 // expose the area drawn
249 expose(0, owner_.workHeight() + old_first - text->first_y,
250 owner_.workWidth(), text->first_y - old_first);
253 // make a dumb new-draw
254 drawFromTo(text, bv, 0, owner_.workHeight(), 0, 0, internal);
255 expose(0, 0, owner_.workWidth(), owner_.workHeight());
258 XSync(fl_get_display(), 0);