- LYXERR(Debug::PAINTING) << "\n\t\t*** END DRAWING ***" << endl;
-
- // and grey out above (should not happen later)
-// lyxerr << "par ascent: " << text.getPar(metrics_info_.p1).ascent() << endl;
- if (metrics_info_.y1 > 0
- && metrics_info_.update_strategy == FullScreenUpdate)
- pain.fillRectangle(0, 0, width_, metrics_info_.y1, Color::bottomarea);
-
- // and possibly grey out below
-// lyxerr << "par descent: " << text.getPar(metrics_info_.p1).ascent() << endl;
- if (metrics_info_.y2 < height_
- && metrics_info_.update_strategy == FullScreenUpdate)
- pain.fillRectangle(0, metrics_info_.y2, width_,
- height_ - metrics_info_.y2, Color::bottomarea);
+
+ // and possibly grey out below
+ pair<pit_type, ParagraphMetrics const *> lastpm = tm.last();
+ int const y2 = lastpm.second->position() + lastpm.second->descent();
+ if (y2 < height_)
+ pain.fillRectangle(0, y2, width_, height_ - y2, Color_bottomarea);
+ break;
+ }
+ LYXERR(Debug::PAINTING, "\n\t\t*** END DRAWING ***");
+
+ // The scrollbar needs an update.
+ updateScrollbar();
+
+ // Normalize anchor for next time
+ pair<pit_type, ParagraphMetrics const *> firstpm = tm.first();
+ pair<pit_type, ParagraphMetrics const *> lastpm = tm.last();
+ for (pit_type pit = firstpm.first; pit <= lastpm.first; ++pit) {
+ ParagraphMetrics const & pm = tm.parMetrics(pit);
+ if (pm.position() + pm.descent() > 0) {
+ d->anchor_pit_ = pit;
+ d->anchor_ypos_ = pm.position();
+ break;
+ }
+ }
+ LYXERR(Debug::PAINTING, "Found new anchor pit = " << d->anchor_pit_
+ << " anchor ypos = " << d->anchor_ypos_);
+}
+
+
+void BufferView::message(docstring const & msg)
+{
+ if (d->gui_)
+ d->gui_->message(msg);
+}
+
+
+void BufferView::showDialog(string const & name)
+{
+ if (d->gui_)
+ d->gui_->showDialog(name, string());
+}
+
+
+void BufferView::showDialog(string const & name,
+ string const & data, Inset * inset)
+{
+ if (d->gui_)
+ d->gui_->showDialog(name, data, inset);
+}
+
+
+void BufferView::updateDialog(string const & name, string const & data)
+{
+ if (d->gui_)
+ d->gui_->updateDialog(name, data);
+}
+
+
+void BufferView::setGuiDelegate(frontend::GuiBufferViewDelegate * gui)
+{
+ d->gui_ = gui;
+}
+
+
+// FIXME: Move this out of BufferView again
+docstring BufferView::contentsOfPlaintextFile(FileName const & fname)
+{
+ if (!fname.isReadableFile()) {
+ docstring const error = from_ascii(strerror(errno));
+ docstring const file = makeDisplayPath(fname.absFilename(), 50);
+ docstring const text =
+ bformat(_("Could not read the specified document\n"
+ "%1$s\ndue to the error: %2$s"), file, error);
+ Alert::error(_("Could not read file"), text);
+ return docstring();
+ }
+
+ if (!fname.isReadableFile()) {
+ docstring const file = makeDisplayPath(fname.absFilename(), 50);
+ docstring const text =
+ bformat(_("%1$s\n is not readable."), file);
+ Alert::error(_("Could not open file"), text);
+ return docstring();
+ }
+
+ // FIXME UNICODE: We don't know the encoding of the file
+ docstring file_content = fname.fileContents("UTF-8");
+ if (file_content.empty()) {
+ Alert::error(_("Reading not UTF-8 encoded file"),
+ _("The file is not UTF-8 encoded.\n"
+ "It will be read as local 8Bit-encoded.\n"
+ "If this does not give the correct result\n"
+ "then please change the encoding of the file\n"
+ "to UTF-8 with a program other than LyX.\n"));
+ file_content = fname.fileContents("local8bit");
+ }
+
+ return normalize_c(file_content);
+}
+
+
+void BufferView::insertPlaintextFile(FileName const & f, bool asParagraph)
+{
+ docstring const tmpstr = contentsOfPlaintextFile(f);
+
+ if (tmpstr.empty())
+ return;
+
+ Cursor & cur = cursor();
+ cap::replaceSelection(cur);
+ buffer_.undo().recordUndo(cur);
+ if (asParagraph)
+ cur.innerText()->insertStringAsParagraphs(cur, tmpstr);
+ else
+ cur.innerText()->insertStringAsLines(cur, tmpstr);
+
+ updateMetrics();
+ buffer_.changed();