]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetgraphics.C
2001-12-28 Lars Gullik Bj�nnes <larsbj@birdstep.com>
[lyx.git] / src / insets / insetgraphics.C
index 72944c62b62ed3bbf88221386f4995684141ad7c..b4f7f7cd5ea4255c4f5d571a557725c3b0ba559f 100644 (file)
@@ -28,10 +28,7 @@ Known BUGS:
        We should probably use what the user asks to use... but when he chooses
        by the file dialog we normally get an absolute path and this may not be 
        what the user meant.
-    * Bug in FileDlg class (src/filedlg.[hC]) when selecting a file and then
-        pressing ok, it counts as if no real selection done. Apparently
-        when choosing a file it doesn't update the select file input line.
-               
+
        * If we are trying to create a file in a read-only directory and there
                are graphics that need converting, the converting will fail because
                it is done in-place, into the same directory as the original image.
@@ -168,6 +165,7 @@ using std::endl;
 
 
 // This function is a utility function
+// ... that should be with ChangeExtension ...
 inline
 string const RemoveExtension(string const & filename)
 {
@@ -256,11 +254,23 @@ int InsetGraphics::width(BufferView *, LyXFont const & font) const
        if (cacheHandle.get() && (pixmap = cacheHandle->getImage()))
                return pixmap->getWidth();
        else {
-               string const msg = statusMessage();
                int font_width = 0;
-               
-               if (!msg.empty())
-                       font_width = lyxfont::width(msg, font);
+
+               LyXFont msgFont(font);
+               msgFont.setFamily(LyXFont::SANS_FAMILY);
+
+               string const justname = OnlyFilename (params.filename);
+               if (!justname.empty()) {
+                       msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
+                       font_width = lyxfont::width(justname, msgFont);
+               }
+
+               string const msg = statusMessage();
+               if (!msg.empty()) {
+                       msgFont.setSize(LyXFont::SIZE_TINY);
+                       int const msg_width = lyxfont::width(msg, msgFont);
+                       font_width = std::max(font_width, msg_width);
+               }
                
                return std::max(50, font_width + 15);
        }
@@ -291,7 +301,8 @@ void InsetGraphics::draw(BufferView * bv, LyXFont const & font,
                
                // Get the image status, default to unknown error.
                GraphicsCacheItem::ImageStatus status = GraphicsCacheItem::UnknownError;
-               if (params.display != InsetGraphicsParams::NONE &&
+               if (lyxrc.display_graphics != "no" &&
+                   params.display != InsetGraphicsParams::NONE &&
                    cacheHandle.get())
                        status = cacheHandle->getImageStatus();
                
@@ -304,22 +315,25 @@ void InsetGraphics::draw(BufferView * bv, LyXFont const & font,
                        return;
                }
 
-               
                paint.rectangle(old_x + 2, baseline - lascent,
                                lwidth - 4,
                                lascent + ldescent);
 
-               string const msg = statusMessage();
-               if (!msg.empty()) {
-                       // Print the message.
-                       LyXFont msgFont(font);
-                       msgFont.setFamily(LyXFont::SANS_FAMILY);
+               // 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);
-                       string const justname = OnlyFilename (params.filename);
                        paint.text(old_x + 8, 
-                                  baseline - lyxfont::maxAscent(msgFont) - 4,
-                                  justname, msgFont);
+                                  baseline - lyxfont::maxAscent(msgFont) - 4,
+                                  justname, msgFont);
+               }
 
+               // Print the message.
+               string const msg = statusMessage();
+               if (!msg.empty()) {
                        msgFont.setSize(LyXFont::SIZE_TINY);
                        paint.text(old_x + 8, baseline - 4, msg, msgFont);
                }
@@ -498,7 +512,7 @@ void formatResize(ostream & os, string const & key,
                break;
 
        case InsetGraphicsParams::SCALE:
-               os << "scale" << '=' << size << ',';
+               os << "scale" << '=' << size/100 << ',';
        }
 }
 
@@ -518,7 +532,7 @@ InsetGraphics::createLatexOptions() const
 
        // Make sure it's not very close to zero, a float can be effectively
        // zero but not exactly zero.
-       if (lyx::float_equal(params.rotateAngle, 0, 0.001)) {
+       if (!lyx::float_equal(params.rotateAngle, 0, 0.001)) {
                options << "angle="
                        << params.rotateAngle << ',';
        }
@@ -768,10 +782,10 @@ void InsetGraphics::validate(LaTeXFeatures & features) const
        if (params.filename.empty())
                return ;
 
-       features.graphicx = true;
+       features.require("graphicx");
 
        if (params.subcaption)
-               features.subfigure = true;
+               features.require("subfigure");
 }
 
 
@@ -784,7 +798,9 @@ void InsetGraphics::updateInset() const
 
        // We do it this way so that in the face of some error, we will still
        // be in a valid state.
-       if (!params.filename.empty()) {
+       if (!params.filename.empty() &&
+           lyxrc.display_graphics != "no" &&
+           params.display != InsetGraphicsParams::NONE) {
                temp = gc.addFile(params.filename);
        }