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"
41 val.foreground = BlackPixel(fl_get_display(),
42 DefaultScreen(fl_get_display()));
44 val.function = GXcopy;
45 val.graphics_exposures = false;
46 val.line_style = LineSolid;
48 return XCreateGC(fl_get_display(), RootWindow(fl_get_display(), 0),
49 GCForeground | GCFunction | GCGraphicsExposures
50 | 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()) return;
82 GC gc = lyxColorHandler->getGCForeground(LColor::cursor);
85 XGetGCValues(fl_get_display(),
86 gc, GCForeground, &val);
87 XChangeGC(fl_get_display(), gc_copy, GCForeground, &val);
91 void XScreen::showManualCursor(LyXText const * text, int x, int y,
92 int asc, int desc, Cursor_Shape shape)
94 // Update the cursor color.
97 int const y1 = max(y - text->first_y - asc, 0);
98 int const y_tmp = min(y - text->first_y + desc,
99 static_cast<int>(owner_.workHeight()));
101 // Secure against very strange situations
102 int const y2 = max(y_tmp, y1);
105 XFreePixmap(fl_get_display(), cursor_pixmap);
109 if (y2 > 0 && y1 < int(owner_.workHeight())) {
110 cursor_pixmap_h = y2 - y1 + 1;
111 cursor_pixmap_y = y1;
119 cursor_pixmap_w = cursor_pixmap_h/3;
122 case REVERSED_L_SHAPE:
123 cursor_pixmap_w = cursor_pixmap_h/3;
124 cursor_pixmap_x = x - cursor_pixmap_w + 1;
129 XCreatePixmap (fl_get_display(),
133 fl_get_visual_depth());
134 XCopyArea (fl_get_display(),
138 owner_.xpos() + cursor_pixmap_x,
139 owner_.ypos() + cursor_pixmap_y,
143 XDrawLine(fl_get_display(),
154 case REVERSED_L_SHAPE:
155 int const rectangle_h = (cursor_pixmap_h + 10) / 20;
156 XFillRectangle(fl_get_display(),
159 cursor_pixmap_x + owner_.xpos(),
160 y2 - rectangle_h + 1 + owner_.ypos(),
161 cursor_pixmap_w - 1, rectangle_h);
166 cursor_visible_ = true;
170 void XScreen::hideCursor()
172 if (!cursor_visible_) return;
175 XCopyArea (fl_get_display(),
180 cursor_pixmap_w, cursor_pixmap_h,
181 cursor_pixmap_x + owner_.xpos(),
182 cursor_pixmap_y + owner_.ypos());
184 cursor_visible_ = false;
188 void XScreen::expose(int x, int y, int exp_width, int exp_height)
190 // FIXME: here we should definitely NOT do this.
191 // we need to generate an expose event for the workarea
192 // and then copy from the pixmap to the screen. This
193 // is the Sane Way (tm)
194 XCopyArea(fl_get_display(),
199 exp_width, exp_height,
205 void XScreen::draw(LyXText * text, BufferView * bv, unsigned int y)
207 if (cursor_visible_) hideCursor();
209 int const old_first = text->first_y;
210 bool internal = (text == bv->text);
213 // is any optimization possible?
214 if ((y - old_first) < owner_.workHeight()
215 && (old_first - y) < owner_.workHeight())
217 if (text->first_y < old_first) {
218 drawFromTo(text, bv, 0,
219 old_first - text->first_y, 0, 0, internal);
220 XCopyArea (fl_get_display(),
227 owner_.workHeight() - old_first + text->first_y,
229 owner_.ypos() + old_first - text->first_y
231 // expose the area drawn
234 old_first - text->first_y);
237 owner_.workHeight() + old_first - text->first_y,
238 owner_.workHeight(), 0, 0, internal);
239 XCopyArea (fl_get_display(),
244 owner_.ypos() + text->first_y - old_first,
246 owner_.workHeight() + old_first - text->first_y,
249 // expose the area drawn
250 expose(0, owner_.workHeight() + old_first - text->first_y,
251 owner_.workWidth(), text->first_y - old_first);
254 // make a dumb new-draw
255 drawFromTo(text, bv, 0, owner_.workHeight(), 0, 0, internal);
256 expose(0, 0, owner_.workWidth(), owner_.workHeight());
259 XSync(fl_get_display(), 0);