Hello,

I'm sending here the patch that should have been in the former archive,
this will complete the update.

Sorry it was completely my mistake.

-- 
  Baruch Even

http://techst02.technion.ac.il/~sbaruch/   (My Site)
http://rpghost.com/jindor/                 (My brothers AD&D site)

" Learn to laugh ... it's the path to true love! " 
   - The Angel in the movie Michael


? src/frontends/xforms/form_graphics.C
? src/frontends/xforms/FormGraphics.h
? src/frontends/xforms/FormGraphics.C
? src/frontends/xforms/form_graphics.h
? src/frontends/xforms/RadioButtonGroup.h
? src/frontends/xforms/RadioButtonGroup.C
? src/frontends/xforms/forms/form_graphics.fd
? src/graphics/.cvsignore
? src/graphics/GraphicsCache.h
? src/graphics/GraphicsCache.C
? src/graphics/Makefile.am
? src/graphics/GraphicsCacheItem.h
? src/graphics/GraphicsCacheItem.C
? src/insets/insetgraphicsParams.C
? src/insets/insetgraphicsParams.h
? src/support/translator.h
Index: ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/ChangeLog,v
retrieving revision 1.456
diff -u -r1.456 ChangeLog
--- ChangeLog   2000/07/28 14:28:52     1.456
+++ ChangeLog   2000/07/31 07:46:42
@@ -1,3 +1,34 @@
+2000-07-31  Baruch Even <[EMAIL PROTECTED]>
+
+    * src/frontends/Dialogs.h: Added showGraphics signals.
+    
+    * src/frontends/xforms/forms/form_graphics.fd: Added file, the xforms
+                    form definition of the graphics dialog.
+
+    * src/frontends/xforms/FormGraphics.h:
+    * src/frontends/xforms/FormGraphics.C: Added files, the GUIndependent
+                    code of InsetGraphics
+    
+    * src/insets/insetgraphics.h:
+    * src/insets/insetgraphics.C: Major writing to make it work.
+
+    * src/insets/insetgraphicsParams.h:
+    * src/insets/insetgraphicsParams.C: Added files, parameter passing struct
+                    between InsetGraphics and GUI.
+
+    * src/LaTeXFeatures.h:
+    * src/LaTeXFeatures.C (c-tor, require, getPackages):
+                    Enabled support for graphicx package.
+
+    * src/buffer.C (parseSingleLyXformat2Token):
+                    Fixed read support for the graphics inset.
+
+    * src/support/translator.h: Added file, used in InsetGraphicsParams. this         
+              is a template to translate between two types.
+
+    * src/frontends/xforms/RadioButtonGroup.h:
+    * src/frontends/xforms/RadioButtonGroup.C: Added files, Comprise a way to
+                    easily control a radio button group.
+
 2000-07-28  Juergen Vigna  <[EMAIL PROTECTED]>
 
        * src/insets/insettabular.C (LocalDispatch): 
Index: configure.in
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/configure.in,v
retrieving revision 1.41
diff -u -r1.41 configure.in
--- configure.in        2000/07/26 15:16:53     1.41
+++ configure.in        2000/07/31 07:46:43
@@ -272,6 +272,7 @@
        po/Makefile.in \
        src/Makefile \
        src/mathed/Makefile \
+       src/graphics/Makefile \
        src/insets/Makefile \
        src/support/Makefile \
        src/xtl/Makefile \
Index: po/POTFILES.in
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/po/POTFILES.in,v
retrieving revision 1.50
diff -u -r1.50 POTFILES.in
--- po/POTFILES.in      2000/07/28 14:28:53     1.50
+++ po/POTFILES.in      2000/07/31 07:46:44
@@ -26,11 +26,12 @@
 src/filedlg.C
 src/FontLoader.C
 src/form1.C
-src/frontends/gnome/Menubar_pimpl.C
 src/frontends/xforms/FormCitation.C
 src/frontends/xforms/form_citation.C
 src/frontends/xforms/FormCopyright.C
 src/frontends/xforms/form_copyright.C
+src/frontends/xforms/FormGraphics.C
+src/frontends/xforms/form_graphics.C
 src/frontends/xforms/FormPreferences.C
 src/frontends/xforms/form_preferences.C
 src/frontends/xforms/FormPrint.C
Index: src/LaTeXFeatures.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/LaTeXFeatures.C,v
retrieving revision 1.20
diff -u -r1.20 LaTeXFeatures.C
--- src/LaTeXFeatures.C 2000/07/17 14:31:06     1.20
+++ src/LaTeXFeatures.C 2000/07/31 07:46:45
@@ -31,7 +31,8 @@
        // packages
        array = false;
        color = false;
-       graphics = false;
+       graphics = false; // INSET_GRAPHICS: remove this when InsetFig is thrown.
+    graphicx = false;
        setspace = false;
        makeidx = false;
        verbatim = false;
@@ -79,11 +80,8 @@
        } else if (name == "color") {
                color = true;
        } else if (name == "graphics") {
-#ifdef USE_GRAPHICX
                graphicx = true;
-#else
-               graphics = true;
-#endif
+               graphics = true;// INSET_GRAPHICS: remove this when InsetFig is 
+thrown.
        } else if (name == "setspace") {
                setspace = true;
        } else if (name == "makeidx") {
@@ -151,6 +149,16 @@
                packages += "\\makeindex\n";
        }
 
+       // graphicx.sty
+       if (graphicx && params.graphicsDriver != "none") {
+               if (params.graphicsDriver == "default")
+                       packages += "\\usepackage{graphicx}\n";
+               else
+                       packages += "\\usepackage[" 
+                               + params.graphicsDriver + "]{graphicx}\n";
+       }
+
+    // INSET_GRAPHICS: remove this when InsetFig is thrown.
        // graphics.sty
        if (graphics && params.graphicsDriver != "none") {
                if (params.graphicsDriver == "default")
Index: src/LaTeXFeatures.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/LaTeXFeatures.h,v
retrieving revision 1.19
diff -u -r1.19 LaTeXFeatures.h
--- src/LaTeXFeatures.h 2000/07/17 14:31:06     1.19
+++ src/LaTeXFeatures.h 2000/07/31 07:46:45
@@ -58,13 +58,10 @@
        bool array;
        ///
        bool color;     // color.sty
-#ifdef USE_GRAPHICX
        ///
        bool graphicx; // graphicx.sty
-#else
        ///
        bool graphics;  // graphics.sty
-#endif
        ///
        bool setspace;  // setspace.sty
        ///
Index: src/Makefile.am
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/Makefile.am,v
retrieving revision 1.48
diff -u -r1.48 Makefile.am
--- src/Makefile.am     2000/07/26 07:09:52     1.48
+++ src/Makefile.am     2000/07/31 07:46:46
@@ -1,5 +1,5 @@
 AUTOMAKE_OPTIONS = foreign
-SUBDIRS = mathed insets support frontends
+SUBDIRS = mathed graphics insets support frontends
 DISTCLEANFILES= *.orig *.rej *~ *.bak core libintl.h config.h
 MAINTAINERCLEANFILES = $(srcdir)/Makefile.in $(srcdir)/config.h.in
 bin_PROGRAMS = lyx
@@ -8,6 +8,7 @@
 ## free to provide another solution... Maybe signals would solve that
 ## magically, but I do not understand them much (JMarc)
 lyx_DEPENDENCIES = mathed/libmathed.la insets/libinsets.la \
+       graphics/libgraphics.la \
        frontends/libfrontends.la @FRONTEND_GUILIB@ \
        frontends/libfrontends.la support/libsupport.la @INCLUDED_SIGC@
 lyx_LDADD = $(lyx_DEPENDENCIES) @INTLLIBS@ $(LYX_LIBS) $(SIGC_LIBS) \
Index: src/buffer.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v
retrieving revision 1.108
diff -u -r1.108 buffer.C
--- src/buffer.C        2000/07/27 08:55:57     1.108
+++ src/buffer.C        2000/07/31 07:46:54
@@ -948,10 +948,11 @@
                        inset->Read(this, lex);
                        par->InsertInset(pos, inset, font);
                        ++pos;
-               } else if (tmptok == "GRAPHICS") {
+               } else if (tmptok == "Graphics") {
                        Inset * inset = new InsetGraphics;
-                               //inset->Read(this, lex);
+            inset->Read(this, lex);
                        par->InsertInset(pos, inset, font);
+            ++pos;
                } else if (tmptok == "LatexCommand") {
                        InsetCommand inscmd;
                        inscmd.Read(this, lex);
@@ -3563,7 +3564,7 @@
        users->owner()->getMiniBuffer()->Set(_("Running Literate..."));   
 
        // Remove all error insets
-       bool a = users->removeAutoInsets();
+       bool removedErrorInsets = users->removeAutoInsets();
 
        // generate the Literate file if necessary
        makeLaTeXFile(lit_name, org_path, false);
@@ -3596,7 +3597,7 @@
 
        // if we removed error insets before we ran LaTeX or if we inserted
        // error insets after we ran LaTeX this must be run:
-        if (a || (res & Literate::ERRORS)){
+        if (removedErrorInsets || (res & Literate::ERRORS)){
                 users->redraw();
                 users->fitCursor();
                 //users->updateScrollbar();
@@ -3630,10 +3631,10 @@
         users->owner()->getMiniBuffer()->Set(_("Building Program..."));   
  
         // Remove all error insets
-        bool a = users->removeAutoInsets();
+        bool removedErrorInsets = users->removeAutoInsets();
  
         // generate the LaTeX file if necessary
-        if (!isNwClean() || a) {
+        if (!isNwClean() || removedErrorInsets) {
                 makeLaTeXFile(lit_name, org_path, false);
                 markNwDirty();
         }
@@ -3667,7 +3668,7 @@
         // if we removed error insets before we ran Literate/Build or
        // if we inserted error insets after we ran Literate/Build this
        // must be run:
-       if (a || (res & Literate::ERRORS)){
+       if (removedErrorInsets || (res & Literate::ERRORS)){
                users->redraw();
                users->fitCursor();
                //users->updateScrollbar();
Index: src/frontends/Dialogs.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/Dialogs.h,v
retrieving revision 1.8
diff -u -r1.8 Dialogs.h
--- src/frontends/Dialogs.h     2000/07/27 10:26:37     1.8
+++ src/frontends/Dialogs.h     2000/07/31 07:47:04
@@ -29,6 +29,7 @@
 // Maybe this should be a UIFunc modelled on LyXFunc
 class LyXView;
 
+class InsetGraphics;
 class InsetBibKey;
 class InsetBibtex;
 class InsetCitation;
@@ -104,7 +105,9 @@
        Signal0<void> showCredits;
        ///
        Signal0<void> showPreferences;
-       ///
+    ///
+    Signal1<void, InsetGraphics *> showGraphics;
+    ///
        Signal1<void, InsetInclude *> showInclude;
        ///
        Signal1<void, InsetIndex *> showIndex;
Index: src/frontends/xforms/Dialogs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/Dialogs.C,v
retrieving revision 1.5
diff -u -r1.5 Dialogs.C
--- src/frontends/xforms/Dialogs.C      2000/07/27 08:55:58     1.5
+++ src/frontends/xforms/Dialogs.C      2000/07/31 07:47:04
@@ -2,9 +2,10 @@
 #include FORMS_H_LOCATION
 
 #include "Dialogs.h"
-#include "FormCitation.h"
 #include "FormCopyright.h"
 #include "FormPreferences.h"
+#include "FormGraphics.h"
+#include "FormCitation.h"
 #include "FormPrint.h"
 #include "FormTabular.h"
 #include "FormUrl.h"
@@ -16,9 +17,10 @@
 
 Dialogs::Dialogs(LyXView * lv)
 {
-       dialogs_.push_back(new FormCitation(lv, this));
        dialogs_.push_back(new FormCopyright(lv, this));
        dialogs_.push_back(new FormPreferences(lv, this));
+    dialogs_.push_back(new FormGraphics(lv, this));
+       dialogs_.push_back(new FormCitation(lv, this));
        dialogs_.push_back(new FormPrint(lv, this));
        dialogs_.push_back(new FormTabular(lv, this));
        dialogs_.push_back(new FormUrl(lv, this));
Index: src/frontends/xforms/Makefile.am
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/Makefile.am,v
retrieving revision 1.6
diff -u -r1.6 Makefile.am
--- src/frontends/xforms/Makefile.am    2000/07/27 10:26:37     1.6
+++ src/frontends/xforms/Makefile.am    2000/07/31 07:47:04
@@ -11,10 +11,6 @@
 ETAGS_ARGS = --lang=c++
 libxforms_la_SOURCES = \
        Dialogs.C \
-       FormCitation.C \
-       FormCitation.h \
-       form_citation.C \
-       form_citation.h \
        FormCopyright.C \
        FormCopyright.h \
        form_copyright.C \
@@ -27,6 +23,14 @@
        FormPrint.h \
        form_print.C \
        form_print.h \
+       FormGraphics.C \
+       FormGraphics.h \
+       form_graphics.C \
+       form_graphics.h \
+       FormCitation.C \
+       FormCitation.h \
+       form_citation.C \
+       form_citation.h \
        FormTabular.C \
        FormTabular.h \
        form_tabular.C \
@@ -41,6 +45,8 @@
        Menubar_pimpl.h \
        input_validators.h \
        input_validators.c \
+       RadioButtonGroup.h \
+       RadioButtonGroup.C \
        xform_macros.h
 
 # These still have to be added. Sooner or later. ARRae-20000411
Index: src/frontends/xforms/forms/makefile
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/forms/makefile,v
retrieving revision 1.8
diff -u -r1.8 makefile
--- src/frontends/xforms/forms/makefile 2000/07/28 04:59:45     1.8
+++ src/frontends/xforms/forms/makefile 2000/07/31 07:47:04
@@ -23,6 +23,7 @@
        form_copyright.fd \
        form_preferences.fd \
        form_print.fd \
+       form_graphics.fd \
        form_tabular.fd \
        form_url.fd
 
Index: src/insets/Makefile.am
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/Makefile.am,v
retrieving revision 1.27
diff -u -r1.27 Makefile.am
--- src/insets/Makefile.am      2000/07/27 08:55:59     1.27
+++ src/insets/Makefile.am      2000/07/31 07:47:04
@@ -39,6 +39,8 @@
        insetfoot.h \
        insetfootlike.C \
        insetfootlike.h \
+       insetgraphicsParams.h \
+       insetgraphicsParams.C \
        insetgraphics.C \
        insetgraphics.h \
        insetinclude.C \
Index: src/insets/insetgraphics.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.C,v
retrieving revision 1.17
diff -u -r1.17 insetgraphics.C
--- src/insets/insetgraphics.C  2000/07/15 23:51:45     1.17
+++ src/insets/insetgraphics.C  2000/07/31 07:47:06
@@ -3,11 +3,149 @@
  * 
  *           LyX, The Document Processor
  *      
- *           Copyright 1995 Matthias Ettrich
  *           Copyright 1995-2000 the LyX Team.
- *
+ *           
+ *           This file Copyright 2000 Baruch Even.
  * ====================================================== */
 
+/*
+How to use it for now:
+    * The lyxfunc 'graphics-insert' will insert this inset into the document.
+*/
+
+/*
+Immediate tasks:
+    * Add the GraphicsCache and FormatTranslator in order to get inline
+        viewing of the figures.
+        
+*/
+
+/*
+Known BUGS:
+    
+    * If the image is from the clipart, and the document is moved to another
+       directory, the user is screwed. Need a way to handle it.
+       This amounts to a problem of when to use relative or absolute file paths
+       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 it
+        when choosing a file it doesn't update the select file input line.
+
+Current PROBLEMS:
+    
+    * How to support both PDF and PS output, should we do the conversion
+        or should we just give the bounding box and tell latex how to do the
+        conversion itself?
+        I (Baruch Even) tend towards doing the conversion ourselves, otherwise
+        we need to give latex quite a few translation commands and from the
+        graphicx package docs it appears that it takes quite a bit of memory
+        on the side of TeXing.
+
+TODO Basics:
+
+    * Add support for more features so that it will be useable as a drop in
+      replacement to insetfig.
+        * Keep aspect ratio radio button
+
+    * Create the GraphicsCache and FormatTranslator
+    * Add inline viewing of image.
+
+TODO Before initial production release:
+    * Replace insetfig everywhere
+        * Read it's file format
+        * Get created by all commands used to create figinset currently.
+        * Search for comments of the form
+            // INSET_GRAPHICS: remove this when InsetFig is thrown.
+          And act upon them.
+
+    * Pop up a dialog if the widget version is higher than what we accept.
+    * Finish the basic To-do list.
+    * Extract the general logic of the dialog in order to allow easier porting
+        to Gnome/KDE, and put the general logic in frontends and the inherited
+        platform dependent code in the appropriate dirs.
+   
+TODO Extended features:
+
+    * Advanced Latex tab folder.
+    * Add even more options to make it better than insetfig.
+        * Support for complete control over the latex parameters for TeXperts
+        * What advanced features the users want to do?
+            Implement them in a non latex dependent way, but a logical way.
+            LyX should translate it to latex or any other fitting format.
+    * Add a way to roll the image file into the file format.
+    * When loading if the image is not found in the expected place, try
+       to find it in the clipart, or in the same directory with the image.
+    * If the dialog had no real change from previous time, do not mark document
+        as changed.
+    * Keep a tab on the image file, if it changes, update the lyx view.
+ */
+
+/* NOTES:
+ *
+ * Intentions:
+ *  This is currently a moving target, I'm trying stuff and learning what
+ *  is needed and how to accomplish it, since there is no predefined goal or
+ *  way to go I invent it as I go.
+ *
+ *  My current intention is for seperation from LaTeX, the basic needs are 
+ *  resizing and rotating, displaying on screen in various depths and printing
+ *  conversion of depths (independent of the display depth). For this I'll 
+ *  provide a simple interface.
+ *
+ *  The medium level includes clipping of the image, but in a limited way.
+ *
+ *  For the LaTeX gurus I'll provide a complete control over the output, but
+ *  this is latex dependent and guru dependent so I'd rather avoid doing this
+ *  for the normal user. This stuff includes clipping, special image size
+ *  specifications (\textwidth\minus 2in) which I see no way to generalize
+ *  to non-latex specific way.
+ *
+ * Used packages:
+ *  'graphicx' for the graphics inclusion.
+ *  'subfigure' for the subfigures.
+ *
+ * Fileformat:
+ *
+ * Current version is 1 (inset file format version), when changing it
+ * it should be changed in the Write() function when writing in one place
+ * and when reading one should change the version check and the error message.
+ *
+ * The filename is kept in  the lyx file in a relative way, so as to allow
+ * moving the document file and its images with no problem.
+ *
+ * Conversions:
+ *  
+ *  Apparently the PNG output is preferred over PDF images when doing PDF
+ *  documents (i.e. prefer imagemagick eps2png over eps2pdf)
+ */
+
+/* Current Stage:
+ *  Embryonic.
+ *
+ * PLAN:
+ *  Finish basic support:
+ *      Inline image viewing
+ *      Get into lyx-devel as an unactivated inset for the benefit of those
+ *          who really need it.
+ *
+ *  Do Release quality support:
+ *      Allow to change display depth
+ *      Make default figure instead of InsetFig
+ *      Add to LyX (probably after 1.1.6 is released)
+ *      
+ *  Extended features:
+ *      Output format conversion
+ *      Print depth changes
+ *      Image file tracking of changes.
+ *
+ *  Extended^2:
+ *      Image roll-in (how? when? why?)
+ *          This means to add the image inside the LyX file, usefull when
+ *          transferring the file around.
+ */
+ 
 #ifdef __GNUG__
 #pragma implementation
 #endif
@@ -15,102 +153,40 @@
 #include <config.h>
 
 #include "insets/insetgraphics.h"
+#include "insets/insetgraphicsParams.h"
+#include "graphics/GraphicsCache.h"
+#include "graphics/GraphicsCacheItem.h"
+ 
+#include "frontends/Dialogs.h"
+#include "LyXView.h"
+#include "buffer.h"
 #include "BufferView.h"
 #include "Painter.h"
-#include "form_graphics.h"
 #include "lyx_gui_misc.h"
 #include "filedlg.h"
 #include "support/FileInfo.h"
 #include "support/filetools.h"
-
-using std::ostream;
-using std::endl;
 
-extern string system_lyxdir;
-extern string user_lyxdir;
-extern string system_tempdir;
-
-string browseFile();
-
-extern "C"
-void GraphicxCB(FL_OBJECT * obj, long arg) 
-{
-       lyxerr << "GraphicxCB: obj = " << obj << " arg = " << arg << endl;
-       switch (arg) {
-       case 0: // The graphics file
-               lyxerr << "Set the graphics file in InsetGraphics" << endl;
-               break;
-       case 1: // The file browser
-               browseFile();
-               break;
-       case 2: // The Apply button
-               lyxerr << "Scan the form and set the "
-                       "InsetGraphics accordingly." << endl;
-               break;
-       case 3: // The OK button
-               GraphicxCB(obj, 2); // do the apply
-               GraphicxCB(obj, 4); // do the cancel
-               break;
-       case 4: // The Cancel button
-               lyxerr << "Just hide the form and do nothing else!" << endl;
-               break;
-       case 99:
-               lyxerr << "Not implemented yet..." << endl;
-               break;
-       default:
-               lyxerr << "Unknown callback value!" << endl;
-               break;
-       }
-}
-
-
-string browseFile()
-{
-       // This function is probably not good enough yet, and does need some
-       // arguemnts to tell what dir to start looking in.
-       
-       static string current_figure_path = ".";
-
-       LyXFileDlg fileDlg;
-
-       // Does user clipart directory exist?
-       string bufclip = AddName (user_lyxdir, "clipart");      
-       FileInfo fileInfo(bufclip);
-       if (!(fileInfo.isOK() && fileInfo.isDir()))
-               // No - bail out to system clipart directory
-               bufclip = AddName (system_lyxdir, "clipart");   
-
+#include "debug.h"
 
-       fileDlg.SetButton(0, _("Clipart"), bufclip); 
 
-       bool error = false;
-       string buf;
-       do {
-               string p = fileDlg.Select(_("Graphics"),
-                                  current_figure_path,
-                                  "*ps", string());
-
-               if (p.empty()) return p;
-
-               current_figure_path = OnlyPath(p);
-
-               if (p.find_first_of("#~$% ") != string::npos) {
-                       WriteAlert(_("Filename can't contain any "
-                                    "of these characters:"),
-                                  // xgettext:no-c-format
-                                  _("space, '#', '~', '$' or '%'.")); 
-                       error = true;
-               }
-       } while (error);
-
-       return buf;
-}
+using std::ostream;
+using std::endl;
 
 
+// Initialize only those variables that do not have a constructor.
 InsetGraphics::InsetGraphics()
-       : form(0)
+#ifdef IG_OLDPARAMS    
+      : use_bb(false), hiresbb(false), angle(0.0), origin(DEFAULT)
+      ,keepaspectratio(false), scale(0.0), clip(false), draft(false)          
+#endif     
 {}
 
+InsetGraphics::~InsetGraphics()
+{
+    // Emits the hide signal to the dialog connected (if any)
+    hide();
+}
 
 int InsetGraphics::ascent(BufferView *, LyXFont const &) const 
 {
@@ -128,9 +204,12 @@
 
 int InsetGraphics::width(BufferView *, LyXFont const &) const 
 {
+    // Need to replace this with data coming from GraphicsCache
+#ifdef IG_OLDPARAMS    
        if (bb.isSet()) {
-               return bb.urx - bb.llx;
+               return bb.urx - bb.llx + 2;
        }
+#endif    
        return 100;
 }
 
@@ -138,34 +217,19 @@
 void InsetGraphics::draw(BufferView * bv, LyXFont const & font,
                         int baseline, float & x, bool) const
 {
-       Painter & pain = bv->painter();
+       Painter & paint = bv->painter();
 
        // This will draw the graphics. As for now we only draw a
        // placeholder rectangele.
-       pain.rectangle(int(x), baseline - ascent(bv, font),
+       paint.rectangle(int(x), baseline - ascent(bv, font),
                       width(bv, font),
                       ascent(bv, font) + descent(bv, font));
 }
 
 
-void InsetGraphics::Edit(BufferView *, int, int, unsigned int)
+void InsetGraphics::Edit(BufferView *bv, int, int, unsigned int)
 {
-       lyxerr.debug() << "InsetGraphics::Edit" << endl;
-
-       if (!form) {
-               form = create_form_Graphics();
-               fl_set_form_atclose(form->Graphics, CancelCloseBoxCB, 0);
-               fl_set_object_return(form->Angle, FL_RETURN_ALWAYS);
-               fl_set_object_return(form->Width, FL_RETURN_ALWAYS);
-               fl_set_object_return(form->Height, FL_RETURN_ALWAYS);
-       }
-
-       if (form->Graphics->visible) {
-               fl_raise_form(form->Graphics);
-       } else {
-               fl_show_form(form->Graphics, FL_PLACE_MOUSE | FL_PLACE_SIZE,
-                            FL_FULLBORDER, _("Graphics"));
-       }
+    bv->owner()->getDialogs() -> showGraphics(this);
 }
 
 
@@ -175,70 +239,197 @@
 }
 
 
-void InsetGraphics::Write(Buffer const *, ostream & os) const
+void InsetGraphics::Write(Buffer const * buf, ostream & os) const
 {
-       // The question on the file format is still open.
-       // Suggestions?
-       // perhaps a format that is xml-parsable
-       //<graphics name="test.eps"/>
-       os << "GRAPHICS\n";
+       os << "Graphics FormatVersion 1" << endl;
+
+    params.Write(buf, os);
 }
 
+#if 0
+// Baruch Even 2000-07-08
+
+// A Thought for another way to read the file...
+// The map should be a static part of the object or a static part of this
+// file and should be filled during program start.
+// The questions are:
+// 1. Is this cleaner?
+// 2. Is there no hidden performance costs?
+// 
+// Regarding 2 I can already see that we will have two copies of the strings
+// one in the data part of the program and one in the map, but that won't be
+// more than say 2K (overestimation here), there is no real benefit to put
+// it in the map since there aren't that many configuration items that will
+// make it a faster solution, it might just be a bit cleaner.
+// (a map stores either in a hash or a kind of a balanced tree).
+
+void InsetGraphics::Read(Buffer const * buf, LyXLex & lex)
+{
+    typedef map<string, enum TOKENS> ReadActionMap;
+    static ReadActionMap const readMap;
+
+    bool finished = false;
+
+    while (lex.IsOK() && !finished) {
+        lex.next();
+
+        string const token = lex.GetString();
+        lyxerr.debug() << "Token: '" << token << '\'' << endl;
+
+        if (token.empty())
+            continue;
+        
+        ReadActionMap::const_iterator it =
+            readMap.find(token);
+
+        if (it == readMap.end()) {
+            lyxerr << "Unknown keyword, skipping." << endl;
+            continue;
+        }
+        
+        switch (it.second) {
+        case FILENAME_TOKEN:
+            break;
+        case VERSION_TOKEN:
+            break;
+        default:
+            break;
+        }
 
-void InsetGraphics::Read(Buffer const *, LyXLex & /*lex*/) 
-{
-       // For now we only use a static file...
-       graphicsfile = "testfile.xpm";
-       //graphicscache.addFile(graphicsfile);
-       //bb = graphicscache.getBB(graphicsfile);
-       //pixmap = graphicscache.getPixmap(graphicsfile);
+            
+    }
 }
+#endif
 
+void InsetGraphics::Read(Buffer const * buf, LyXLex & lex) 
+{
+    bool finished = false;
+    
+    while (lex.IsOK() && !finished) {
+        lex.next();
+        
+        string const token = lex.GetString();
+        lyxerr.debug() << "Token: '" << token << '\'' << endl;
+
+        if (token.empty()) {
+            continue;
+        } else if (token == "\\end_inset") {
+            finished = true;
+        } else if (token == "FormatVersion") {
+            lex.next();
+            int version = lex.GetInteger();
+            if (version > 1)
+                lyxerr 
+                    << "This document was created with a newer Graphics widget"
+                       ", You should use a newer version of LyX to read this"
+                       " file."
+                    << endl;
+            // TODO: Possibly open up a dialog?
+        } else {
+            if (! params.Read(buf, lex, token))
+                lyxerr << "Unknown token, " << token << ",skipping." << endl;
+        }
+    }
+    
+    updateInset();
+}
+
+static void formatResize(ostream & os, char const *key,
+        InsetGraphicsParams::Resize resizeType, double size)
+{
+    switch (resizeType) {
+    case InsetGraphicsParams::DEFAULT_SIZE:
+        break;
+    
+    case InsetGraphicsParams::CM:
+        os << key << '=' << size << "cm,";
+        break;
+            
+    case InsetGraphicsParams::INCH:
+        os << key << '=' << size << "in,";
+        break;
+            
+    case InsetGraphicsParams::PERCENT_PAGE:
+        os << key << '=' << size/100 << "\\text" << key << ',';
+        break;
+            
+    case InsetGraphicsParams::PERCENT_COLUMN:
+        os << key << '=' << size/100 << "\\column" << key << ',';
+        break;
+            
+    }
+}
 
-int InsetGraphics::Latex(Buffer const *, ostream & os,
+int InsetGraphics::Latex(Buffer const *buf, ostream & os,
                         bool /*fragile*/, bool/*fs*/) const
 {
        // MISSING: We have to decide how to do the order of the options
-       // that is depentant of order, like witdth, height, andlge. Should
+       // that is dependent of order, like witdth, height, angle. Should
        // we rotate before scale? Should we let the user decide?
        // bool rot_before_scale; ?
-       // Nothing to do if we don't have a graphics file
-       if (graphicsfile.empty()) return 0;
 
-       // We never used the starred form, we use the "clip" option instead.
-       string command("\\insetgraphics");
-       
+    // (BE) As a first step we should do a scale before rotate since this is
+    // more like the natural thought of how to do it.
+    // (BE) I believe that a priority list presented to the user with
+    // a default order would be the best, though it would be better to
+    // hide such a thing in an "Advanced options" dialog.
+    // (BE) This should go an advanced LaTeX options dialog.
+
+    // If there is no file specified, just output a message about it in
+    // the latex output.
+    if (params.filename.empty()) {
+        os << "\\fbox{\\rule[-0.5in]{0pt}{1in}"
+           << _("empty figure path")
+           << '}'
+           << endl;
+
+        return 1;
+    }
+
+    // Calculate the options part of the command, we must do it to a string
+    // stream since we might have a trailing comma that we would like to remove
+    // before writing it to the output stream.
 #ifdef HAVE_SSTREAM
        std::ostringstream options;
 #else
        ostrstream options;
 #endif
+    
+    formatResize(options, "width", params.widthResize, params.widthSize);
+    formatResize(options, "height", params.heightResize, params.heightSize);
+
+    if (params.rotateAngle != 0) {
+        options << "angle="
+            << params.rotateAngle << ',';
+    }
+    
+#ifdef IG_OLDPARAMS    
        if (bb.isSet() && use_bb) {
                options << "bb="
-                       << bb.llx << " " << bb.lly << " "
-                       << bb.urx << " " << bb.ury << ",";
+                       << bb.llx << ' ' << bb.lly << ' '
+                       << bb.urx << ' ' << bb.ury << ',';
        }
        if (hiresbb) {
                options << "hiresbb,";
        }
        if (viewport.isSet()) {
                options << "viewport="
-                       << viewport.llx << " " << viewport.lly << " "
-                       << viewport.urx << " " << viewport.ury << ",";
+                       << viewport.llx << ' ' << viewport.lly << ' '
+                       << viewport.urx << ' ' << viewport.ury << ',';
        }
        if (trim.isSet()) {
                options << "trim="
-                       << trim.llx << " " << trim.lly << " "
-                       << trim.urx << " " << trim.ury << ",";
+                       << trim.llx << ' ' << trim.lly << ' '
+                       << trim.urx << ' ' << trim.ury << ',';
        }
-       if (natheight.value() == 0) {
-               options << "natheight=" << natheight.asString() << ",";
+       if (natheight.value() != 0) {
+               options << "natheight=" << natheight.asString() << ',';
        }
-       if (natwidth.value() == 0) {
-               options << "natwidth=" << natwidth.asString() << ",";
+       if (natwidth.value() != 0) {
+               options << "natwidth=" << natwidth.asString() << ',';
        }
        if (angle != 0.0) {
-               options << "angle=" << angle << ",";
+               options << "angle=" << angle << ',';
        }
        if (origin != DEFAULT) {
                switch(origin) {
@@ -282,19 +473,19 @@
                }
        }
        if (g_width.value() != 0) {
-               options << "width=" << g_width.asString() << ",";
+               options << "width=" << g_width.asString() << ',';
        }
        if (g_height.value() != 0) {
-               options << "height=" << g_height.asString() << ",";
+               options << "height=" << g_height.asString() << ',';
        }
        if (totalheight.value() != 0) {
-               options << "totalheight=" << totalheight.asString() << ",";
+               options << "totalheight=" << totalheight.asString() << ',';
        }
        if (keepaspectratio) {
                options << "keepaspectratio,";
        }
        if (scale != 0.0) {
-               options << "scale=" << scale << ",";
+               options << "scale=" << scale << ',';
        }
        if (clip) {
                options << "clip,";
@@ -303,17 +494,21 @@
                options << "draft,";
        }
        if (!type.empty()) {
-               options << "type=" << type << ",";
-       }
-       if (!ext.empty()) {
-               options << "ext=" << type << ",";
-       }
-       if (!read.empty()) {
-               options << "read=" << type << ",";
-       }
-       if (!command.empty()) {
-               options << "command=" << type << ",";
-       }
+               options << "type=" << type << ',';
+       
+        // These should be present only when type is used.
+           if (!ext.empty()) {
+                   options << "ext=" << type << ',';
+           }
+           if (!read.empty()) {
+                   options << "read=" << type << ',';
+           }
+           if (!command.empty()) {
+                   options << "command=" << type << ',';
+           }
+    }
+#endif
+
 #ifdef HAVE_SSTREAM
        string opts(options.str().c_str());
 #else
@@ -323,48 +518,126 @@
        delete [] tmp;
 #endif
        opts = strip(opts, ',');
+
+    
+    // If it's not an inline image, surround it with the centering paragraph.
+    if (! params.inlineFigure) {
+        os << endl 
+            << "\\vspace{0.3cm}" << endl
+            << "{\\par\\centering ";
+    }
+   
+    // Do we want subcaptions?
+    if (params.subcaption) {
+        os << "\\subfigure[" << params.subcaptionText << "]{";
+    }
+    
+       // We never used the starred form, we use the "clip" option instead.
+    os << "\\includegraphics";
+
        if (!opts.empty()) {
-               command += "[";
-               command += opts;
-               command += "]";
-       }
-       command += "{";
-       command += graphicsfile;
-       command += "}";
+               os << '[' << opts << ']';
+       }
 
-       os << command << '\n';
-       
+    // Make the filename relative to the lyx file
+    string filename = MakeRelPath(params.filename, OnlyPath(buf->fileName()));
+
+    // and remove the extension so the LaTeX will use whatever is
+    // appropriate (when there are several versions in different formats)
+    filename = ChangeExtension(filename, string());
+
+       os << '{' << filename << '}';
+
+    // Do we want a subcaption?
+    if (params.subcaption) {
+        // Close the subcaption command
+        os << '}';
+    }
+    
+    // Is this an inline graphics?
+    if (!params.inlineFigure) {
+        os  << " \\par}" << endl
+            << "\\vspace{0.3cm}" << endl;
+    }
+
+    // How do we decide to what format should we export?
+//    cachehandle->export(ImageType::EPS);
+//    cachehandle->export(ImageType::PNG);
+        
        return 1;
 }
 
 
 int InsetGraphics::Ascii(Buffer const *, ostream &) const
 {
+    // No graphics in ascii output.
        return 0;
 }
 
 
 int InsetGraphics::Linuxdoc(Buffer const *, ostream &) const
 {
+    // No graphics in LinuxDoc output. Should check how/what to add.
        return 0;
 }
 
 
 int InsetGraphics::DocBook(Buffer const *, ostream &) const
 {
+    // No graphics in DocBook output. Should check how/what to add.
        return 0;
 }
 
 
-void InsetGraphics::Validate(LaTeXFeatures & /*features*/) const
+void InsetGraphics::Validate(LaTeXFeatures & features) const
 {
-       //features.graphicx = true;
+    // If we have no image, we should not require anything.
+    if (params.filename.empty())
+        return;
+
+       features.graphicx = true;
+
+    if (params.subcaption)
+        features.subfigure = true;
 }
 
+// Update the inset after parameters changed (read from file or changed in
+// dialog.
+void InsetGraphics::updateInset()
+{
+    // If file changed...
+       //graphicscache.addFile(params.filename);
+       //bb = graphicscache.getBB(params.filename);
+       //pixmap = graphicscache.getPixmap(params.filename);
+}
 
-Inset * InsetGraphics::Clone() const
+bool InsetGraphics::setParams(InsetGraphicsParams const & params)
 {
-       return new InsetGraphics;
+    // TODO: Make it return true only when the data has been changed.
+    // for this to work we still need to implement operator == in 
+    // InsetGraphicsParams
+    if (this->params == params)
+        return false;
+
+    // Copy the new parameters.
+    this->params = params;
+
+    // Update the inset with the new parameters.
+    updateInset();
+   
+    // We have changed data, report it.
+    return true;
 }
 
+InsetGraphicsParams InsetGraphics::getParams() const
+{
+    return params;
+}
 
+Inset * InsetGraphics::Clone() const
+{
+    InsetGraphics * newInset = new InsetGraphics;
+    newInset->setParams(getParams());
+    
+       return newInset;
+}
Index: src/insets/insetgraphics.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.h,v
retrieving revision 1.15
diff -u -r1.15 insetgraphics.h
--- src/insets/insetgraphics.h  2000/07/15 23:51:45     1.15
+++ src/insets/insetgraphics.h  2000/07/31 07:47:07
@@ -17,17 +17,26 @@
 #endif
 
 #include "insets/lyxinset.h"
+#include "insets/insetgraphicsParams.h"
+
 #include "LaTeXFeatures.h"
-#include "vspace.h"
-#include "insets/BoundingBox.h"
+
+// We need a signal here to hide an active dialog when we are deleted.
+#include "sigc++/signal_system.h"
+#ifdef SIGC_CXX_NAMESPACES
+using SigC::Signal0;
+#endif
 
-struct FD_Graphics;
+class Dialogs;
+class GraphicsCacheItem;
 
 ///
 class InsetGraphics : public Inset {
 public:
        ///
        InsetGraphics();
+    ///
+    ~InsetGraphics();
        ///
        int ascent(BufferView *, LyXFont const &) const;
        ///
@@ -44,6 +53,7 @@
        void Write(Buffer const *, std::ostream &) const;
        ///
        void Read(Buffer const *, LyXLex & lex);
+
        /** returns the number of rows (\n's) of generated tex code.
         fragile == true means, that the inset should take care about
         fragile commands by adding a \protect before.
@@ -57,7 +67,9 @@
        ///
        int DocBook(Buffer const *, std::ostream &) const;
 
-       /// Updates needed features for this inset.
+       /** Tell LyX what the latex features you need i.e. what latex packages
+     * you need to be included.
+     */
        void Validate(LaTeXFeatures & features) const;
 
        /// returns LyX code associated with the inset. Used for TOC, ...)
@@ -65,28 +77,37 @@
   
        ///
        Inset * Clone() const;
-       /// Set the graphics file
-       void graphicsFile(string const & f) {
-               graphicsfile = f;
-       }
-       /// Get the graphics file
-       string const & graphicsFile() const {
-               return graphicsfile;
-       }
+
+    /// Set the inset parameters, used by the GUIndependent dialog.
+    /// Return true of new params are different from what was so far.
+    bool setParams(InsetGraphicsParams const & params);
+
+    /// Get the inset parameters, used by the GUIndependent dialog.
+    InsetGraphicsParams getParams() const;
+
+    /// This signal is connected by our dialog and called when the inset
+    /// is deleted.
+    Signal0<void> hide;
 private:
-       ///
-       FD_Graphics * form;
-       ///
-       string graphicsfile;
-       ///
-       Pixmap pixmap;
-       
+    /// Update the inset after parameter change.
+    void updateInset();
+
+    /// The graphics cache handle.
+    GraphicsCacheItem * cachehandle;
+
+
+    InsetGraphicsParams params;
+
+    // Baruch Even ([EMAIL PROTECTED]) 2000-07-17
+    // This was the intended way however it is not flexible enough and
+    // only provides for LaTeX output.
+#ifdef IG_OLDPARAMS
        // We need variables to store the size of the boundingbox and
        // to store a pointer to the pixmap in.. The question is if
        // these should be in a "pixmap" class.
        // We also need to have variables about rotation and scaling,
        // width and height. in effect all the paramters that
-       // \includegrapichs can handle. (the graphix.sty package)
+       // \includegraphics can handle. (the graphix.sty package)
 
        /** The "bounding box" of the graphics image. Its value field
            must contain four dimensions, separated by spaces.  */
@@ -101,76 +122,77 @@
            and then for HiResBoundingBox, and set hiresbb depending on this.
            This key makes LaTeX search for %%HiResBoundingBox comments
            instead of the normal %%BoundingBox. Some applications use
-           this to specify more precise bounding boxes, becase the cumbers
+           this to specify more precise bounding boxes, becase the numbers
            can normally only have integer values. It is a Boolean, either
            "true" or "false". */
        bool hiresbb;
+    
        /** This key takes four arguments (like bb), but in this case the
            origin is taken with respect to the bounding box specified in
            the file. So to view a 20 bp square at the lower left-hand corner
            of the picture, specify viewport=0 0 20 20. */
        BoundingBox viewport;
+    
        /** Similar to the viewport key, but the four dimensions correspond
            to the amount of space to be trimmed (cut off) at the left-hand
            side, bottom, right-hand side and top of the included graphics. */
        BoundingBox trim;
+    
        /// Natural height of figure
        LyXLength natheight;
+    
        /// Natural width of figure.
        LyXLength natwidth;
+   
        /// Rotation angle (in degrees, counterclockwise).
        float angle;
-       /// This is the different origins that the graphicx package support.
-       enum Origin {
-               DEFAULT,
-               LEFTTOP,
-               LEFTCENTER,
-               LEFTBASELINE,
-               LEFTBOTTOM,
-               CENTERTOP,
-               CENTER,
-               CENTERBASELINE,
-               CENTERBOTTOM,
-               RIGHTTOP,
-               RIGHTCENTER,
-               RIGHTBASELINE,
-               RIGHTBOTTOM,
-               REFERENCE_POINT = LEFTBASELINE
-       };
+
        /** Origin for rotation, similar to the origin parameter of
            the \rotatebox command described on p.46 and Fig. 2.2 on p.46. */
        Origin origin;
+    
        /// Required width (the width of the image is scaled to that value).
        LyXLength g_width;
+    
        /// Required height (the height of the image is scaled to that value).
        LyXLength g_height;
+    
        /** Required total height (the total height of the image is scaled
            to that value). This key should be used instead of height if
            images are rotated over 90 degrees, since the height can
            disappear (and become the depth) and LaTeX will have difficulties
            satisfying the user's request. */
        LyXLength totalheight;
+    
        /** Boolean variable that can have the values "true" and "false"
            (se above for defaults). When true, specifying both width and
            height parameters does not distort the picture, but the image
            is scaled so that neither of the width of height exceeds the
            given dimensions. */
        bool keepaspectratio;
+    
        /// Scale factor
        float scale;
+    
        /** Clip the graphic to the bounding box. It is a Boolean, either
            "true" or "false". */
        bool clip;
+    
        /// Locally switch to draft mode. A Boolean valued key, like clip.
        bool draft;
+    
        /// The graphics type.
        string type;
-       ///x The file extension of the file containing the image data.
+    
+       /// The file extension of the file containing the image data.
        string ext;
+    
        /// The file extension of the file "read" by LaTeX.
        string read;
+    
        /// Any command to be applied to the file.
        string command;
+#endif    
 };
 
 #endif
Index: src/support/Makefile.am
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/Makefile.am,v
retrieving revision 1.20
diff -u -r1.20 Makefile.am
--- src/support/Makefile.am     2000/07/27 10:26:38     1.20
+++ src/support/Makefile.am     2000/07/31 07:47:07
@@ -55,5 +55,6 @@
        syscontr.C \
        syscontr.h \
        syssingleton.C \
+       translator.h \
        textutils.h \
        utility.hpp

Reply via email to