]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/screen.C
* disable loading of xpm files by the xforms image loader.
[lyx.git] / src / frontends / screen.C
index 1d38beafcc0aa1b4a3b588820808c734a645058f..cac90a4c7a1f7f16f6a54db868fac332f855fb62 100644 (file)
@@ -1,9 +1,11 @@
 /**
  * \file screen.C
- * Copyright 2002 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author John Levon <moz@compsoc.man.ac.uk>
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
  *
  * Splash screen code added by Angus Leeming
  */
@@ -16,6 +18,7 @@
 
 #include "screen.h"
 #include "lyxtext.h"
+#include "lyxrc.h"
 #include "lyxrow.h"
 #include "BufferView.h"
 #include "buffer.h"
 #include "lyxfont.h"
 #include "version.h"
 
-#include "graphics/GraphicsCache.h"
-#include "graphics/GraphicsCacheItem.h"
+#include "graphics/GraphicsLoader.h"
 #include "graphics/GraphicsImage.h"
-#include "graphics/GraphicsParams.h"
 
 #include "support/filetools.h" // LibFileSearch
 
 #include <boost/utility.hpp>
 #include <boost/bind.hpp>
+#include <boost/signals/trackable.hpp>
 
 using std::min;
 using std::max;
@@ -45,36 +47,25 @@ using std::endl;
 
 namespace {
 
-class SplashScreen : boost::noncopyable {
+class SplashScreen : boost::noncopyable, boost::signals::trackable {
 public:
        /// This is a singleton class. Get the instance.
        static SplashScreen const & get();
        ///
-       grfx::GImage const * image() const { return graphic_->image().get(); }
+       grfx::Image const * image() const { return loader_.image(); }
        ///
        string const & text() const { return text_; }
        ///
        LyXFont const & font() const { return font_; }
 
 private:
-       /** Make the c-tor, d-tor private so we can control how many objects
+       /** Make the c-tor private so we can control how many objects
         *  are instantiated.
         */
        SplashScreen();
-       ///
-       ~SplashScreen();
 
-       /** Connected to grfx::GCacheItem::statusChanged, so will generate the
-        *  pixmap as soon as the file is loaded into memory.
-        */
-       void createPixmap();
-       
-       /** Must store a copy of the cached item to ensure that it is not
-        *  erased unexpectedly by the cache itself.
-        */
-       grfx::GraphicPtr graphic_;
-       /// The loading status of the image.
-       grfx::ImageStatus status_;
+       ///
+       grfx::Loader loader_;
        /// The text to be written on top of the pixmap
        string const text_;
        /// in this font...
@@ -90,10 +81,12 @@ SplashScreen const & SplashScreen::get()
 
 
 SplashScreen::SplashScreen()
-       : status_(grfx::WaitingToLoad),
-         text_(lyx_version ? lyx_version : "unknown")
+       : text_(lyx_version ? lyx_version : "unknown")
 {
-       string const file = LibFileSearch("images", "banner", "xpm");
+       if (!lyxrc.show_banner)
+               return;
+
+       string const file = LibFileSearch("images", "banner", "ppm");
        if (file.empty())
                return;
 
@@ -104,54 +97,13 @@ SplashScreen::SplashScreen()
        font_.setColor(LColor::yellow);
 
        // Load up the graphics file
-       grfx::GCache & gc = grfx::GCache::get();
-       if (!gc.inCache(file))
-               gc.add(file);
-       // We /must/ make a local copy of this.
-       graphic_ = gc.graphic(file);
-
-       if (graphic_->status() == grfx::Loaded) {
-               createPixmap();
-       } else {
-               graphic_->statusChanged.connect(
-                       boost::bind(&SplashScreen::createPixmap, this));
-               graphic_->startLoading();
-       }
-}
-
-
-SplashScreen::~SplashScreen()
-{
-       if (!graphic_.get())
-               return;
-
-       string const file = graphic_->filename();
-       graphic_.reset();
-
-       // If only the cache itself now references this item, then it will be
-       // removed.
-       grfx::GCache::get().remove(file);
-}
-
-
-void SplashScreen::createPixmap()
-{
-       if (!graphic_.get() || status_ != grfx::WaitingToLoad)
-               return;
-
-       // We aren't going to modify the image, so don't bother making a
-       // local copy
-       grfx::GImage * const image = graphic_->image().get();
-       if (!image)
-               return;
-
-       if (image->getPixmap()) {
-               status_ = grfx::Loaded;
-               return;
-       }
-
-       bool const success = image->setPixmap(grfx::GParams());
-       status_ = success ? grfx::Loaded : grfx::ErrorLoading;
+       loader_.reset(file);
+       // We aren't interested here in when the image is loaded.
+       // If it isn't ready when we want it, then we ignore it.
+//     loader_->statusChanged.connect(
+//                     boost::bind(&SplashScreen::statusChanged, this));
+       if (loader_.status() == grfx::WaitingToLoad)
+               loader_.startLoading();
 }
 
 } // namespace anon
@@ -219,6 +171,7 @@ bool LyXScreen::fitManualCursor(BufferView * bv, LyXText * text,
                text->first_y = newtop;
                return true;
        }
+
        return false;
 }
 
@@ -243,8 +196,7 @@ unsigned int LyXScreen::topCursorVisible(LyXCursor const & cursor, int top_y)
        if (!row)
                return max(newtop, 0);
 
-       if (cursor.y() - row->baseline() + row->height()
-           - top_y >= vheight) {
+       if (cursor.y() - row->baseline() + row->height() - top_y >= vheight) {
                if (row->height() < vheight
                    && row->height() > vheight / 4) {
                        newtop = cursor.y()
@@ -279,8 +231,10 @@ bool LyXScreen::fitCursor(LyXText * text, BufferView * bv)
        // Is a change necessary?
        int const newtop = topCursorVisible(text->cursor, text->first_y);
        bool const result = (newtop != text->first_y);
-       if (result)
+       if (result) {
                draw(text, bv, newtop);
+       }
+
        return result;
 }
 
@@ -430,19 +384,19 @@ void LyXScreen::greyOut()
 
        // Add a splash screen to the centre of the work area
        SplashScreen const & splash = SplashScreen::get();
-       grfx::GImage const * const splash_image = splash.image();
+       grfx::Image const * const splash_image = splash.image();
        if (splash_image) {
                int const w = splash_image->getWidth();
                int const h = splash_image->getHeight();
 
-               int x = 0.5 * (workarea().workWidth() - w);
-               int y = 0.5 * (workarea().workHeight() - h);
+               int x = (workarea().workWidth() - w) / 2;
+               int y = (workarea().workHeight() - h) / 2;
 
                workarea().getPainter().image(x, y, w, h, *splash_image);
 
                string const & splash_text  = splash.text();
                LyXFont const & splash_font = splash.font();
-               
+
                x += 260;
                y += 265;
 
@@ -455,7 +409,7 @@ void LyXScreen::drawFromTo(LyXText * text, BufferView * bv,
        int y1, int y2, int yo, int xo,
        bool internal)
 {
-       lyxerr[Debug::GUI] << "screen: drawFromTo " << y1 << "-" << y2 << endl;
+       lyxerr[Debug::GUI] << "screen: drawFromTo " << y1 << '-' << y2 << endl;
 
        int y_text = text->first_y + y1;