]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/GraphicsImage.h
Use UTF8 for LaTeX export.
[lyx.git] / src / graphics / GraphicsImage.h
index a9931ef7217260f8b336cdb3e8ed8593b991a160..5364aa1dbb7263c3e3321f5514cf2addbb4fcc21 100644 (file)
 // -*- C++ -*-
 /**
- *  \file GraphicsImage.h
- *  Copyright 2002 the LyX Team
- *  Read the file COPYING
+ * \file GraphicsImage.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *  \author Baruch Even <baruch.even@writeme.com>
- *  \author Angus Leeming <a.leeming@ic.ac.uk>
+ * \author Baruch Even
+ * \author Angus Leeming
  *
- *  An abstract base class for the images themselves.
- *  Allows the user to retrieve the pixmap, once loaded and to issue commands
- *  to modify it.
+ * Full author contact details are available in file CREDITS.
  *
- *  The signals newImage and loadableFormats are connected to the approriate
- *  derived classes elsewhere, allowing the graphics cache to access them
- *  without knowing anything about their instantiation.
+ * An abstract base class for the images themselves.
+ * Allows the user to retrieve the pixmap, once loaded and to issue commands
+ * to modify it.
  *
- *  The loading process can be asynchronous, but cropping, rotating and
- *  scaling block execution.
+ * The boost::functions newImage and loadableFormats are connected to the
+ * appropriate derived classes elsewhere, allowing the graphics cache to
+ * access them without knowing anything about their instantiation.
+ *
+ * The loading process can be asynchronous, but cropping, rotating and
+ * scaling block execution.
  */
 
 #ifndef GRAPHICSIMAGE_H
 #define GRAPHICSIMAGE_H
 
-#include "LString.h"
-#include "GraphicsTypes.h"
-
+#include <boost/function.hpp>
 #include <boost/shared_ptr.hpp>
-
-#include <boost/signals/signal0.hpp>
-#include <boost/signals/signal1.hpp>
-
-#include <X11/X.h>
+#include <boost/signal.hpp>
 
 #include <vector>
 #include <utility>
 
-#ifdef __GNUG__
-#pragma interface
-#endif
+namespace lyx {
+namespace graphics {
 
-namespace grfx {
+class Params;
 
-class GParams;
-
-class GImage
-{
+class Image {
 public:
-       /// A list of supported formats.
-       typedef std::vector<string> FormatList;
-       /** This will be connected to a function that will return whichever
-        *  derived class we desire.
+       /** This is to be connected to a function that will return a new
+        *  instance of a viable derived class.
         */
-       static boost::signal0<ImagePtr> newImage;
+       typedef boost::shared_ptr<Image> ImagePtr;
+       ///
+       static boost::function<ImagePtr()> newImage;
 
+       ///
+       typedef std::vector<std::string> FormatList;
        /// Return the list of loadable formats.
-       static boost::signal0<FormatList> loadableFormats;
+       static boost::function<FormatList()> loadableFormats;
 
        ///
-       virtual ~GImage() {}
+       virtual ~Image() {}
 
        /// Create a copy
-       virtual GImage * clone() const = 0;
-
-       ///
-       virtual Pixmap getPixmap() const = 0;
+       Image * clone() const;
 
        /// Get the image width
-       virtual unsigned int getWidth() const = 0;
+       unsigned int getWidth() const;
 
        /// Get the image height
-       virtual unsigned int getHeight() const = 0;
+       unsigned int getHeight() const;
 
-       /** At the end of the loading or modification process, return the new
-        *  image by emitting this signal */
-       typedef boost::signal1<void, bool> SignalType;
+       /// Is the image drawable ?
+       bool isDrawable() const;
+
+       /** At the end of the loading process inform the outside world
+        *  by emitting a signal
+        */
+       typedef boost::signal<void(bool)> SignalType;
        ///
-       typedef boost::shared_ptr<SignalType> SignalTypePtr;
+       SignalType finishedLoading;
 
-       /// Start loading the image file.
-       virtual void load(string const & filename, SignalTypePtr) = 0;
+       /** Start loading the image file.
+        *  The caller should expect this process to be asynchronous and
+        *  so should connect to the "finished" signal above.
+        */
+       void load(std::string const & filename);
 
        /** Generate the pixmap.
         *  Uses the params to decide on color, grayscale etc.
         *  Returns true if the pixmap is created.
         */
-       virtual bool setPixmap(GParams const & params) = 0;
+       bool setPixmap(Params const & params);
 
        /// Clip the image using params.
-       virtual void clip(GParams const & params) = 0;
+       void clip(Params const & params);
 
        /// Rotate the image using params.
-       virtual void rotate(GParams const & params) = 0;
+       void rotate(Params const & params);
 
        /// Scale the image using params.
-       virtual void scale(GParams const & params) = 0;
+       void scale(Params const & params);
 
 protected:
+       /// Must define default c-tor explicitly as we define a copy c-tor.
+       Image() {}
+       /// Don't copy the signal finishedLoading
+       Image(Image const &) {}
+
        /** Uses the params to ascertain the dimensions of the scaled image.
         *  Returned as make_pair(width, height).
-        *  If something geso wrong, returns make_pair(getWidth(), getHeight())
+        *  If something goes wrong, returns make_pair(getWidth(), getHeight())
         */
        std::pair<unsigned int, unsigned int>
-       getScaledDimensions(GParams const & params) const;
+       getScaledDimensions(Params const & params) const;
+
+private:
+       /// Create a copy
+       virtual Image * clone_impl() const = 0;
+       /// Get the image width
+       virtual unsigned int getWidth_impl() const = 0;
+
+       /// Get the image height
+       virtual unsigned int getHeight_impl() const = 0;
+
+       /// is the image drawable ?
+       virtual bool isDrawable_impl() const = 0;
+
+       /** Start loading the image file.
+        *  The caller should expect this process to be asynchronous and
+        *  so should connect to the "finished" signal above.
+        */
+       virtual void load_impl(std::string const & filename) = 0;
+
+       /** Generate the pixmap.
+        *  Uses the params to decide on color, grayscale etc.
+        *  Returns true if the pixmap is created.
+        */
+       virtual bool setPixmap_impl(Params const & params) = 0;
+
+       /// Clip the image using params.
+       virtual void clip_impl(Params const & params) = 0;
+
+       /// Rotate the image using params.
+       virtual void rotate_impl(Params const & params) = 0;
+
+       /// Scale the image using params.
+       virtual void scale_impl(Params const & params) = 0;
 };
 
-} // namespace grfx
+
+inline
+Image * Image::clone() const
+{
+       return clone_impl();
+}
+
+
+inline
+unsigned int Image::getWidth() const
+{
+       return getWidth_impl();
+}
+
+
+inline
+unsigned int Image::getHeight() const
+{
+       return getHeight_impl();
+}
+
+
+inline
+bool Image::isDrawable() const
+{
+       return isDrawable_impl();
+}
+
+
+inline
+void Image::load(std::string const & filename)
+{
+       return load_impl(filename);
+}
+
+
+inline
+bool Image::setPixmap(Params const & params)
+{
+       return setPixmap_impl(params);
+}
+
+
+inline
+void Image::clip(Params const & params)
+{
+       return clip_impl(params);
+}
+
+
+inline
+void Image::rotate(Params const & params)
+{
+       return rotate_impl(params);
+}
+
+
+inline
+void Image::scale(Params const & params)
+{
+       return scale_impl(params);
+}
+
+} // namespace graphics
+} // namespace lyx
 
 #endif // GRAPHICSIMAGE_H