3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
21 #include "QWorkArea.h"
25 #include "BufferView.h"
26 #include "insets/insettext.h"
29 #include <qapplication.h>
37 /// copy some horizontal regions about inside a pixmap
38 void copyInPixmap(QPixmap * p, int dest_y, int src_y, int src_w, int src_h)
40 // bitBlt(dest, dest_x, dest_y, source, src_x, src_y, src_w, src_h)
41 bitBlt(p, 0, dest_y, p, 0, src_y, src_w, src_h);
47 QScreen::QScreen(QWorkArea & o)
48 : LyXScreen(), owner_(o)
58 void QScreen::showManualCursor(LyXText const * text, int x, int y,
59 int asc, int desc, Cursor_Shape shape)
61 if (!qApp->focusWidget())
64 string const focusname(qApp->focusWidget()->name());
67 if (focusname != "content_pane")
70 int const y1 = max(y - text->first_y - asc, 0);
71 int const y_tmp = min(y - text->first_y + desc, owner_.height());
73 // secure against very strange situations
74 // which would be when .... ?
75 int const y2 = max(y_tmp, y1);
77 if (y2 > 0 && y1 < owner_.height()) {
78 cursor_h_ = y2 - y1 + 1;
87 cursor_w_ = cursor_h_ / 3;
90 case REVERSED_L_SHAPE:
91 cursor_w_ = cursor_h_ / 3;
92 cursor_x_ = x - cursor_w_ + 1;
96 if (!nocursor_pixmap_.get()
97 || cursor_w_ != nocursor_pixmap_->width()
98 || cursor_h_ != nocursor_pixmap_->height()) {
99 nocursor_pixmap_.reset(new QPixmap(cursor_w_, cursor_h_));
102 owner_.getPainter().start();
105 bitBlt(nocursor_pixmap_.get(), 0, 0, owner_.getPixmap(),
106 cursor_x_, cursor_y_, cursor_w_, cursor_h_);
108 owner_.getPainter().line(x, y1, x, y2);
113 case REVERSED_L_SHAPE:
114 int const rectangle_h = (cursor_h_ + 10) / 20;
115 owner_.getPainter().fillRectangle(
116 cursor_x_, y2 - rectangle_h + 1,
117 cursor_w_ - 1, rectangle_h, LColor::cursor);
121 owner_.getPainter().end();
123 owner_.getContent()->repaint(
124 cursor_x_, cursor_y_,
125 cursor_w_, cursor_h_);
128 cursor_visible_ = true;
132 void QScreen::hideCursor()
134 if (!cursor_visible_)
137 bitBlt(owner_.getPixmap(), cursor_x_, cursor_y_,
138 nocursor_pixmap_.get(), 0, 0, cursor_w_, cursor_h_);
140 owner_.getContent()->repaint(
141 cursor_x_, cursor_y_,
142 cursor_w_, cursor_h_);
144 cursor_visible_ = false;
148 void QScreen::repaint()
150 QWidget * content(owner_.getContent());
151 content->repaint(0, 0, content->width(), content->height());
155 void QScreen::expose(int x, int y, int w, int h)
157 lyxerr[Debug::GUI] << "expose " << w << "x" << h
158 << "+" << x << "+" << y << endl;
160 owner_.getContent()->update(x, y, w, h);
164 void QScreen::draw(LyXText * text, BufferView * bv, unsigned int y)
166 QPixmap * p(owner_.getPixmap());
168 owner_.getPainter().start();
170 if (cursor_visible_) hideCursor();
172 int const old_first = text->first_y;
173 bool const internal = (text == bv->text);
176 // If you want to fix the warning below, fix it so it
177 // actually scrolls properly. Hint: a cast won't do.
179 // is any optimization possible?
180 if (y - old_first < owner_.workHeight()
181 && old_first - y < owner_.workHeight()) {
182 if (text->first_y < old_first) {
183 int const dest_y = old_first - text->first_y;
184 drawFromTo(text, bv, 0, dest_y, 0, 0, internal);
185 copyInPixmap(p, dest_y, 0, owner_.workWidth(), owner_.height() - dest_y);
186 expose(0, 0, owner_.workWidth(), dest_y);
188 int const src_y = text->first_y - old_first;
189 drawFromTo(text, bv, owner_.height() - src_y, owner_.height(), 0, 0, internal);
190 copyInPixmap(p, 0, 0, owner_.workWidth(), owner_.height() - src_y);
191 expose(0, owner_.height() - src_y, owner_.workWidth(), src_y);
194 lyxerr[Debug::GUI] << "dumb full redraw" << endl;
195 drawFromTo(text, bv, 0, owner_.height(), 0, 0, internal);
199 owner_.getPainter().end();