3 * Read the file COPYING
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
20 #include "frontends/screen.h"
21 #include "frontends/font_metrics.h"
22 #include "XWorkArea.h"
29 #include "BufferView.h"
30 #include "insets/insettext.h"
31 #include "ColorHandler.h"
44 val.foreground = BlackPixel(fl_get_display(),
45 DefaultScreen(fl_get_display()));
47 val.function = GXcopy;
48 val.graphics_exposures = false;
49 val.line_style = LineSolid;
51 return XCreateGC(fl_get_display(), RootWindow(fl_get_display(), 0),
52 GCForeground | GCFunction | GCGraphicsExposures
53 | GCLineWidth | GCLineStyle, &val);
60 XScreen::XScreen(XWorkArea & o)
61 : LyXScreen(), owner_(o)
63 // the cursor isnt yet visible
77 XFreeGC(fl_get_display(), gc_copy);
81 void XScreen::setCursorColor()
83 if (!lyxColorHandler.get()) return;
85 GC gc = lyxColorHandler->getGCForeground(LColor::cursor);
88 XGetGCValues(fl_get_display(),
89 gc, GCForeground, &val);
90 XChangeGC(fl_get_display(), gc_copy, GCForeground, &val);
94 void XScreen::showManualCursor(LyXText const * text, int x, int y,
95 int asc, int desc, Cursor_Shape shape)
97 // Update the cursor color.
100 int const y1 = max(y - text->first_y - asc, 0);
101 int const y_tmp = min(y - text->first_y + desc,
102 static_cast<int>(owner_.workHeight()));
104 // Secure against very strange situations
105 int const y2 = max(y_tmp, y1);
108 XFreePixmap(fl_get_display(), cursor_pixmap);
112 if (y2 > 0 && y1 < int(owner_.workHeight())) {
113 cursor_pixmap_h = y2 - y1 + 1;
114 cursor_pixmap_y = y1;
122 cursor_pixmap_w = cursor_pixmap_h/3;
125 case REVERSED_L_SHAPE:
126 cursor_pixmap_w = cursor_pixmap_h/3;
127 cursor_pixmap_x = x - cursor_pixmap_w + 1;
132 XCreatePixmap (fl_get_display(),
136 fl_get_visual_depth());
137 XCopyArea (fl_get_display(),
141 owner_.xpos() + cursor_pixmap_x,
142 owner_.ypos() + cursor_pixmap_y,
146 XDrawLine(fl_get_display(),
157 case REVERSED_L_SHAPE:
158 int const rectangle_h = (cursor_pixmap_h + 10) / 20;
159 XFillRectangle(fl_get_display(),
162 cursor_pixmap_x + owner_.xpos(),
163 y2 - rectangle_h + 1 + owner_.ypos(),
164 cursor_pixmap_w - 1, rectangle_h);
169 cursor_visible_ = true;
173 void XScreen::hideCursor()
175 if (!cursor_visible_) return;
178 XCopyArea (fl_get_display(),
183 cursor_pixmap_w, cursor_pixmap_h,
184 cursor_pixmap_x + owner_.xpos(),
185 cursor_pixmap_y + owner_.ypos());
187 cursor_visible_ = false;
191 void XScreen::expose(int x, int y, int w, int h)
193 lyxerr[Debug::GUI] << "expose " << w << "x" << h
194 << "+" << x << "+" << y << endl;
195 XCopyArea(fl_get_display(),
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 const 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);