3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
6 * \author John Levon <moz@compsoc.man.ac.uk>
12 #pragma implementation
19 #include "QWorkArea.h"
23 #include "BufferView.h"
24 #include "insets/insettext.h"
27 #include <qapplication.h>
35 /// copy some horizontal regions about inside a pixmap
36 void copyInPixmap(QPixmap * p, int dest_y, int src_y, int src_w, int src_h)
39 0, dest_y, // dest x,y
40 p, 0, src_y, // source x, y
41 src_w, src_h // source w, h
48 QScreen::QScreen(QWorkArea & o)
49 : LyXScreen(), owner_(o)
59 void QScreen::showManualCursor(LyXText const * text, int x, int y,
60 int asc, int desc, Cursor_Shape shape)
62 if (!qApp->focusWidget())
65 string const focusname(qApp->focusWidget()->name());
68 if (focusname != "content_pane")
71 int const y1 = max(y - text->first_y - asc, 0);
72 int const y_tmp = min(y - text->first_y + desc, owner_.height());
74 // secure against very strange situations
75 // which would be when .... ?
76 int const y2 = max(y_tmp, y1);
78 if (y2 > 0 && y1 < owner_.height()) {
79 cursor_h_ = y2 - y1 + 1;
88 cursor_w_ = cursor_h_ / 3;
91 case REVERSED_L_SHAPE:
92 cursor_w_ = cursor_h_ / 3;
93 cursor_x_ = x - cursor_w_ + 1;
97 if (!nocursor_pixmap_.get()
98 || cursor_w_ != nocursor_pixmap_->width()
99 || cursor_h_ != nocursor_pixmap_->height()) {
100 nocursor_pixmap_.reset(new QPixmap(cursor_w_, cursor_h_));
103 owner_.getPainter().start();
106 bitBlt(nocursor_pixmap_.get(), 0, 0, owner_.getPixmap(),
107 cursor_x_, cursor_y_, cursor_w_, cursor_h_);
109 owner_.getPainter().line(x, y1, x, y2);
114 case REVERSED_L_SHAPE:
115 int const rectangle_h = (cursor_h_ + 10) / 20;
116 owner_.getPainter().fillRectangle(
117 cursor_x_, y2 - rectangle_h + 1,
118 cursor_w_ - 1, rectangle_h, LColor::cursor);
122 owner_.getPainter().end();
124 owner_.getContent()->repaint(
125 cursor_x_, cursor_y_,
126 cursor_w_, cursor_h_);
129 cursor_visible_ = true;
133 void QScreen::hideCursor()
135 if (!cursor_visible_)
138 bitBlt(owner_.getPixmap(), cursor_x_, cursor_y_,
139 nocursor_pixmap_.get(), 0, 0, cursor_w_, cursor_h_);
141 owner_.getContent()->repaint(
142 cursor_x_, cursor_y_,
143 cursor_w_, cursor_h_);
145 cursor_visible_ = false;
149 void QScreen::repaint()
151 QWidget * content(owner_.getContent());
152 content->repaint(0, 0, content->width(), content->height());
156 void QScreen::expose(int x, int y, int w, int h)
158 lyxerr[Debug::GUI] << "expose " << w << "x" << h
159 << "+" << x << "+" << y << endl;
161 owner_.getContent()->update(x, y, w, h);
165 void QScreen::draw(LyXText * text, BufferView * bv, unsigned int y)
167 QPixmap * p(owner_.getPixmap());
169 owner_.getPainter().start();
171 if (cursor_visible_) hideCursor();
173 int const old_first = text->first_y;
174 bool const internal = (text == bv->text);
177 // If you want to fix the warning below, fix it so it
178 // actually scrolls properly. Hint: a cast won't do.
180 // is any optimization possible?
181 if (y - old_first < owner_.workHeight()
182 && old_first - y < owner_.workHeight()) {
183 if (text->first_y < old_first) {
184 int const dest_y = old_first - text->first_y;
185 drawFromTo(text, bv, 0, dest_y, 0, 0, internal);
186 copyInPixmap(p, dest_y, 0, owner_.workWidth(), owner_.height() - dest_y);
187 expose(0, 0, owner_.workWidth(), dest_y);
189 int const src_y = text->first_y - old_first;
190 drawFromTo(text, bv, owner_.height() - src_y, owner_.height(), 0, 0, internal);
191 copyInPixmap(p, 0, 0, owner_.workWidth(), owner_.height() - src_y);
192 expose(0, owner_.height() - src_y, owner_.workWidth(), src_y);
195 lyxerr[Debug::GUI] << "dumb full redraw" << endl;
196 drawFromTo(text, bv, 0, owner_.height(), 0, 0, internal);
200 owner_.getPainter().end();