3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS
18 #include "frontends/screen.h"
19 #include "frontends/font_metrics.h"
20 #include "XWorkArea.h"
27 #include "BufferView.h"
28 #include "insets/insettext.h"
29 #include "ColorHandler.h"
42 val.foreground = BlackPixel(fl_get_display(),
43 DefaultScreen(fl_get_display()));
45 val.function = GXcopy;
46 val.graphics_exposures = false;
47 val.line_style = LineSolid;
49 return XCreateGC(fl_get_display(), RootWindow(fl_get_display(), 0),
50 GCForeground | GCFunction | GCGraphicsExposures
51 | GCLineWidth | GCLineStyle, &val);
57 XScreen::XScreen(XWorkArea & o)
58 : LyXScreen(), owner_(o)
60 // the cursor isnt yet visible
74 XFreeGC(fl_get_display(), gc_copy);
78 void XScreen::setCursorColor()
80 if (!lyxColorHandler.get())
83 GC gc = lyxColorHandler->getGCForeground(LColor::cursor);
86 XGetGCValues(fl_get_display(),
87 gc, GCForeground, &val);
88 XChangeGC(fl_get_display(), gc_copy, GCForeground, &val);
92 void XScreen::showManualCursor(LyXText const * text, int x, int y,
93 int asc, int desc, Cursor_Shape shape)
95 // Update the cursor color.
98 int const y1 = max(y - text->top_y() - asc, 0);
99 int const y_tmp = min(y - text->top_y() + desc,
100 static_cast<int>(owner_.workHeight()));
102 // Secure against very strange situations
103 int const y2 = max(y_tmp, y1);
106 XFreePixmap(fl_get_display(), cursor_pixmap);
110 if (y2 > 0 && y1 < int(owner_.workHeight())) {
111 cursor_pixmap_h = y2 - y1 + 1;
112 cursor_pixmap_y = y1;
120 cursor_pixmap_w = cursor_pixmap_h/3;
123 case REVERSED_L_SHAPE:
124 cursor_pixmap_w = cursor_pixmap_h/3;
125 cursor_pixmap_x = x - cursor_pixmap_w + 1;
130 XCreatePixmap (fl_get_display(),
134 fl_get_visual_depth());
135 XCopyArea (fl_get_display(),
139 owner_.xpos() + cursor_pixmap_x,
140 owner_.ypos() + cursor_pixmap_y,
144 XDrawLine(fl_get_display(),
155 case REVERSED_L_SHAPE:
156 int const rectangle_h = (cursor_pixmap_h + 10) / 20;
157 XFillRectangle(fl_get_display(),
160 cursor_pixmap_x + owner_.xpos(),
161 y2 - rectangle_h + 1 + owner_.ypos(),
162 cursor_pixmap_w - 1, rectangle_h);
167 cursor_visible_ = true;
171 void XScreen::hideCursor()
173 if (!cursor_visible_) return;
176 XCopyArea (fl_get_display(),
181 cursor_pixmap_w, cursor_pixmap_h,
182 cursor_pixmap_x + owner_.xpos(),
183 cursor_pixmap_y + owner_.ypos());
185 cursor_visible_ = false;
189 void XScreen::expose(int x, int y, int w, int h)
191 lyxerr[Debug::GUI] << "expose " << w << 'x' << h
192 << '+' << x << '+' << y << endl;
193 XCopyArea(fl_get_display(),
203 void XScreen::draw(LyXText * text, BufferView * bv, unsigned int y)
208 int const old_first = text->top_y();
211 // is any optimization possible?
212 if ((y - old_first) < owner_.workHeight()
213 && (old_first - y) < owner_.workHeight())
215 if (text->top_y() < old_first) {
216 drawFromTo(text, bv, 0, old_first - text->top_y(), 0, 0);
217 XCopyArea(fl_get_display(),
224 owner_.workHeight() - old_first + text->top_y(),
226 owner_.ypos() + old_first - text->top_y()
228 // expose the area drawn
231 old_first - text->top_y());
234 owner_.workHeight() + old_first - text->top_y(),
235 owner_.workHeight(), 0, 0);
236 XCopyArea(fl_get_display(),
241 owner_.ypos() + text->top_y() - old_first,
243 owner_.workHeight() + old_first - text->top_y(),
246 // expose the area drawn
247 expose(0, owner_.workHeight() + old_first - text->top_y(),
248 owner_.workWidth(), text->top_y() - old_first);
251 // make a dumb new-draw
252 drawFromTo(text, bv, 0, owner_.workHeight(), 0, 0);
253 expose(0, 0, owner_.workWidth(), owner_.workHeight());
256 XSync(fl_get_display(), 0);