- return cache_->view.lock().get();
-}
-
-
-void InsetGraphics::draw(BufferView * bv, LyXFont const & font,
- int baseline, float & x, bool) const
-{
- // MakeAbsPath returns params().filename unchanged if it absolute
- // already.
- string const file_with_path =
- MakeAbsPath(params().filename, bv->buffer()->filePath());
-
- // A 'paste' operation creates a new inset with the correct filepath,
- // but then the 'old' inset stored in the 'copy' operation is actually
- // added to the buffer.
- // Thus, we should ensure that the filepath is correct.
- if (file_with_path != cache_->loader.filename())
- cache_->update(file_with_path);
-
- cache_->view = bv->owner()->view();
- int oasc = cache_->old_ascent;
-
- int ldescent = descent(bv, font);
- int lascent = ascent(bv, font);
- int lwidth = width(bv, font);
-
- // we may have changed while someone other was drawing us so better
- // to not draw anything as we surely call to redraw ourself soon.
- // This is not a nice thing to do and should be fixed properly somehow.
- // But I still don't know the best way to go. So let's do this like this
- // for now (Jug 20020311)
- if (lascent != oasc)
- return;
-
- // Make sure now that x is updated upon exit from this routine
- int old_x = int(x);
- x += lwidth;
-
- grfx::Params const & gparams = params().as_grfxParams();
-
- if (gparams.display != grfx::NoDisplay &&
- cache_->loader.status() == grfx::WaitingToLoad)
- cache_->loader.startLoading();
-
- if (!cache_->loader.monitoring())
- cache_->loader.startMonitoring();
-
- // This will draw the graphics. If the graphics has not been loaded yet,
- // we draw just a rectangle.
- Painter & paint = bv->painter();
-
- if (imageIsDrawable()) {
- paint.image(old_x + TEXT_TO_INSET_OFFSET, baseline - lascent,
- lwidth - 2 * TEXT_TO_INSET_OFFSET, lascent + ldescent,
- *cache_->loader.image());
-
- } else {
-
- paint.rectangle(old_x + TEXT_TO_INSET_OFFSET, baseline - lascent,
- lwidth - 2 * TEXT_TO_INSET_OFFSET, lascent + ldescent);
-
- // Print the file name.
- LyXFont msgFont(font);
- msgFont.setFamily(LyXFont::SANS_FAMILY);
- string const justname = OnlyFilename (params().filename);
- if (!justname.empty()) {
- msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
- paint.text(old_x + TEXT_TO_INSET_OFFSET + 6,
- baseline - font_metrics::maxAscent(msgFont) - 4,
- justname, msgFont);
- }
-
- // Print the message.
- string const msg = statusMessage();
- if (!msg.empty()) {
- msgFont.setSize(LyXFont::SIZE_TINY);
- paint.text(old_x + TEXT_TO_INSET_OFFSET + 6, baseline - 4, msg, msgFont);
- }
- }
-
- // the status message may mean we changed size, so indicate
- // we need a row redraw
-#if 0
- if (old_status_ != grfx::ErrorUnknown && old_status_ != cached_status_) {
- bv->getLyXText()->status(bv, LyXText::CHANGED_IN_DRAW);
- }
-#endif
-
- // Reset the cache, ready for the next draw request
-#if 0
- cached_status_ = grfx::ErrorUnknown;
- cached_image_.reset();
- cache_filled_ = false;
-#endif