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
15 #pragma implementation
21 #include "frontends/screen.h"
22 #include "frontends/font_metrics.h"
23 #include "XWorkArea.h"
30 #include "BufferView.h"
31 #include "insets/insettext.h"
32 #include "ColorHandler.h"
45 val.foreground = BlackPixel(fl_get_display(),
46 DefaultScreen(fl_get_display()));
48 val.function = GXcopy;
49 val.graphics_exposures = false;
50 val.line_style = LineSolid;
52 return XCreateGC(fl_get_display(), RootWindow(fl_get_display(), 0),
53 GCForeground | GCFunction | GCGraphicsExposures
54 | GCLineWidth | GCLineStyle, &val);
61 XScreen::XScreen(XWorkArea & o)
62 : LyXScreen(), owner_(o)
64 // the cursor isnt yet visible
78 XFreeGC(fl_get_display(), gc_copy);
82 void XScreen::setCursorColor()
84 if (!lyxColorHandler.get()) return;
86 GC gc = lyxColorHandler->getGCForeground(LColor::cursor);
89 XGetGCValues(fl_get_display(),
90 gc, GCForeground, &val);
91 XChangeGC(fl_get_display(), gc_copy, GCForeground, &val);
95 void XScreen::showManualCursor(LyXText const * text, int x, int y,
96 int asc, int desc, Cursor_Shape shape)
98 // Update the cursor color.
101 int const y1 = max(y - text->first_y - asc, 0);
102 int const y_tmp = min(y - text->first_y + desc,
103 static_cast<int>(owner_.workHeight()));
105 // Secure against very strange situations
106 int const y2 = max(y_tmp, y1);
109 XFreePixmap(fl_get_display(), cursor_pixmap);
113 if (y2 > 0 && y1 < int(owner_.workHeight())) {
114 cursor_pixmap_h = y2 - y1 + 1;
115 cursor_pixmap_y = y1;
123 cursor_pixmap_w = cursor_pixmap_h/3;
126 case REVERSED_L_SHAPE:
127 cursor_pixmap_w = cursor_pixmap_h/3;
128 cursor_pixmap_x = x - cursor_pixmap_w + 1;
133 XCreatePixmap (fl_get_display(),
137 fl_get_visual_depth());
138 XCopyArea (fl_get_display(),
142 owner_.xpos() + cursor_pixmap_x,
143 owner_.ypos() + cursor_pixmap_y,
147 XDrawLine(fl_get_display(),
158 case REVERSED_L_SHAPE:
159 int const rectangle_h = (cursor_pixmap_h + 10) / 20;
160 XFillRectangle(fl_get_display(),
163 cursor_pixmap_x + owner_.xpos(),
164 y2 - rectangle_h + 1 + owner_.ypos(),
165 cursor_pixmap_w - 1, rectangle_h);
170 cursor_visible_ = true;
174 void XScreen::hideCursor()
176 if (!cursor_visible_) return;
179 XCopyArea (fl_get_display(),
184 cursor_pixmap_w, cursor_pixmap_h,
185 cursor_pixmap_x + owner_.xpos(),
186 cursor_pixmap_y + owner_.ypos());
188 cursor_visible_ = false;
192 void XScreen::expose(int x, int y, int w, int h)
194 lyxerr[Debug::GUI] << "expose " << w << "x" << h
195 << "+" << x << "+" << y << endl;
196 XCopyArea(fl_get_display(),
206 void XScreen::draw(LyXText * text, BufferView * bv, unsigned int y)
208 if (cursor_visible_) hideCursor();
210 int const old_first = text->first_y;
211 bool const internal = (text == bv->text);
214 // is any optimization possible?
215 if ((y - old_first) < owner_.workHeight()
216 && (old_first - y) < owner_.workHeight())
218 if (text->first_y < old_first) {
219 drawFromTo(text, bv, 0,
220 old_first - text->first_y, 0, 0, internal);
221 XCopyArea (fl_get_display(),
228 owner_.workHeight() - old_first + text->first_y,
230 owner_.ypos() + old_first - text->first_y
232 // expose the area drawn
235 old_first - text->first_y);
238 owner_.workHeight() + old_first - text->first_y,
239 owner_.workHeight(), 0, 0, internal);
240 XCopyArea (fl_get_display(),
245 owner_.ypos() + text->first_y - old_first,
247 owner_.workHeight() + old_first - text->first_y,
250 // expose the area drawn
251 expose(0, owner_.workHeight() + old_first - text->first_y,
252 owner_.workWidth(), text->first_y - old_first);
255 // make a dumb new-draw
256 drawFromTo(text, bv, 0, owner_.workHeight(), 0, 0, internal);
257 expose(0, 0, owner_.workWidth(), owner_.workHeight());
260 XSync(fl_get_display(), 0);