]> git.lyx.org Git - features.git/commitdiff
use real LyXLength for minipages; new method LyXLength::inPixels
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 17 Jan 2002 23:09:31 +0000 (23:09 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 17 Jan 2002 23:09:31 +0000 (23:09 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3412 a592a061-630c-0410-9148-cb99ea01b6c8

14 files changed:
src/BufferView_pimpl.C
src/ChangeLog
src/buffer.C
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlMinipage.h
src/frontends/xforms/ChangeLog
src/frontends/xforms/FormMinipage.C
src/insets/ChangeLog
src/insets/insetminipage.C
src/insets/insetminipage.h
src/insets/insettabular.C
src/lyxlength.C
src/lyxlength.h
src/vspace.C

index 11506b505e4237eaff2e99df4b8123146c689989..b0d7bdbdebef77fe146bd3bc64d83309884de513 100644 (file)
@@ -3302,7 +3302,7 @@ void BufferView::Pimpl::smartQuote()
        
        if (style.pass_thru ||
                (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
-               Dispatch(LFUN_SELFINSERT, "\"");
+               bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
 }
 
 
index 76cd984f9dcced0f0655274f732c52e03367765e..975827fc0034c4708042a0f741e3f55ab97408a5 100644 (file)
@@ -1,3 +1,13 @@
+2002-01-17  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
+
+       * buffer.C (parseSingleLyXformat2Token): update because minipage
+       width is now a LyXLength
+
+       * lyxlength.C (inPixels): new method, extracted from VSpace::inPixels
+
+       * BufferView_pimpl.C (smartQuote): fix insertion of quote inset in
+       math insets
+
 2002-01-17  Juergen Vigna  <jug@sad.it>
 
        * lyxfunc.C (dispatch): fixed PARAGRAPH_GOTO
index c396b1ebad48504f473786ba631814c9454908a6..e2ee6861970d85616b4b1b913c25e225ba55492b 100644 (file)
@@ -1278,10 +1278,10 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                        }
                        InsetMinipage * mini = new InsetMinipage;
                        mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
-                       mini->pageWidth(par->params().pextraWidth());
+                       mini->pageWidth(LyXLength(par->params().pextraWidth()));
                        if (!par->params().pextraWidthp().empty()) {
-                           lyxerr << "WP:" << mini->pageWidth() << endl;
-                           mini->pageWidth(tostr(par->params().pextraWidthp())+"%");
+                           lyxerr << "WP:" << mini->pageWidth().asString() << endl;
+                           mini->pageWidth(LyXLength((par->params().pextraWidthp())+"%"));
                        }
                        Paragraph * op = mini->firstParagraph();
                        mini->inset.paragraph(par);
@@ -1359,10 +1359,10 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
 
                InsetMinipage * mini = new InsetMinipage;
                mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
-               mini->pageWidth(minipar->params().pextraWidth());
+               mini->pageWidth(LyXLength(minipar->params().pextraWidth()));
                if (!par->params().pextraWidthp().empty()) {
-                   lyxerr << "WP:" << mini->pageWidth() << endl;
-                   mini->pageWidth(tostr(par->params().pextraWidthp())+"%");
+                   lyxerr << "WP:" << mini->pageWidth().asString() << endl;
+                   mini->pageWidth(LyXLength((par->params().pextraWidthp())+"%"));
                }
                mini->inset.paragraph(minipar);
                        
index b32614b81ee5724814bd06c11ae3a3df82dfb214..266cc9a6a19d06b2615d9e1a2b1d661b655c1080 100644 (file)
@@ -1,5 +1,7 @@
 2002-01-17  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
 
+       * ControlMinipage.h: change MinipageParams::pageWidth to LyXLength
+
        * ControlExternal.C (Browse): add a std:: qualifier
 
 2002-01-16  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
index b0edc466f1804513d3b2e14f5e0e37d928c4ecff..0e9a9e7187a0328a47ea40571c615f3d7b99a50b 100644 (file)
@@ -34,7 +34,7 @@ struct MinipageParams {
        ///
        MinipageParams(InsetMinipage const &);
        ///
-       string pageWidth;
+       LyXLength pageWidth;
        ///
        InsetMinipage::Position pos;
 };
index 310909aa47401eb9e786ed39cd043f3aabdf279c..029e8eb244b55e2aefa95af9b44fe0f845c2e278 100644 (file)
@@ -1,3 +1,8 @@
+2002-01-17  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
+
+       * FormMinipage.C (apply): change because MinipageParams::pageWidth
+       is now a real LyXLength
+
 2002-01-17  John Levon  <moz@compsoc.man.ac.uk>
 
        * FormDocument.C: enable line spacing input properly
index b06603c76b1c295cedb78ff216b34504bd1c1abb..4e9ec3a12645f46e548a2f353cbde73db341ceef 100644 (file)
@@ -60,8 +60,8 @@ void FormMinipage::build()
 void FormMinipage::apply()
 {
        controller().params().pageWidth =
-               getLengthFromWidgets(dialog_->input_width,
-                       dialog_->choice_width_units);
+               LyXLength(getLengthFromWidgets(dialog_->input_width,
+                       dialog_->choice_width_units));
 
        if (fl_get_button(dialog_->radio_top))
                controller().params().pos = InsetMinipage::top;
index ef5bcda5beaa118ffceae56a18e797d25cb2756f..3374d6ac7ae17275354f18b17d09cdffd05392ab 100644 (file)
@@ -1,3 +1,10 @@
+2002-01-17  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
+
+       * insettabular.C (getMaxWidthOfCell): use LyXLength::inPixels
+
+       * insetminipage.[Ch]: change width_ and height_ to be LyXLength
+       instead of string
+
 2002-01-17  Juergen Vigna  <jug@sad.it>
 
        * insettabular.C (lockInsetInInset): same change as in insettext.
index 8ab1df6a96523380ef40a5c186c113ea59a148e2..dcb8f6018b48784b97969fdf7a5a5a1546b8574e 100644 (file)
@@ -61,7 +61,7 @@ using std::endl;
 
 InsetMinipage::InsetMinipage()
        : InsetCollapsable(), pos_(center),
-         inner_pos_(inner_center)
+         inner_pos_(inner_center), width_(100, LyXLength::PW)
 {
        setLabel(_("minipage"));
        LyXFont font(LyXFont::ALL_SANE);
@@ -79,7 +79,6 @@ InsetMinipage::InsetMinipage()
        setBackgroundColor(LColor::green);
        inset.setFrameColor(0, LColor::blue);
        setInsetName("Minipage");
-       width_ = "100%"; // set default to 100% of column_width
 }
 
 
@@ -107,8 +106,8 @@ void InsetMinipage::write(Buffer const * buf, ostream & os) const
        os << getInsetName() << "\n"
           << "position " << pos_ << "\n"
           << "inner_position " << inner_pos_ << "\n"
-          << "height \"" << height_ << "\"\n"
-          << "width \"" << width_ << "\"\n";
+          << "height \"" << height_.asString() << "\"\n"
+          << "width \"" << width_.asString() << "\"\n";
        InsetCollapsable::write(buf, os);
 }
 
@@ -146,7 +145,7 @@ void InsetMinipage::read(Buffer const * buf, LyXLex & lex)
                string const token = lex.getString();
                if (token == "height") {
                        lex.next();
-                       height_ = lex.getString();
+                       height_ = LyXLength(lex.getString());
                } else {
                        lyxerr << "InsetMinipage::Read: Missing 'height'-tag!"
                                   << endl;
@@ -159,7 +158,7 @@ void InsetMinipage::read(Buffer const * buf, LyXLex & lex)
                string const token = lex.getString();
                if (token == "width") {
                        lex.next();
-                       width_ = lex.getString();
+                       width_ = LyXLength(lex.getString());
                } else {
                        lyxerr << "InsetMinipage::Read: Missing 'width'-tag!"
                                   << endl;
@@ -241,7 +240,7 @@ int InsetMinipage::latex(Buffer const * buf,
                break;
        }
        os << "\\begin{minipage}[" << s_pos << "]{"
-          << LyXLength(width_).asLatexString() << "}%\n";
+          << width_.asLatexString() << "}%\n";
        
        int i = inset.latex(buf, os, fragile, fp);
 
@@ -286,13 +285,13 @@ void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip)
 }
 
 
-string const & InsetMinipage::pageHeight() const
+LyXLength const & InsetMinipage::pageHeight() const
 {
        return height_;
 }
 
 
-void InsetMinipage::pageHeight(string const & ll)
+void InsetMinipage::pageHeight(LyXLength const & ll)
 {
        if (height_ != ll) {
                height_ = ll;
@@ -301,13 +300,13 @@ void InsetMinipage::pageHeight(string const & ll)
 }
 
 
-string const & InsetMinipage::pageWidth() const
+LyXLength const & InsetMinipage::pageWidth() const
 {
        return width_;
 }
 
 
-void InsetMinipage::pageWidth(string const & ll)
+void InsetMinipage::pageWidth(LyXLength const & ll)
 {
        if (ll != width_) {
                width_ = ll;
@@ -332,17 +331,16 @@ int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
        {
                return -1;
        }
-       if (!width_.empty()) {
-               LyXLength len(width_);
-               switch(len.unit()) {
+       if (!width_.zero()) {
+               switch(width_.unit()) {
                case LyXLength::PW: // Always % of workarea
                case LyXLength::PE:
                case LyXLength::PP:
                case LyXLength::PL:
-                       return (InsetCollapsable::getMaxWidth(bv, inset) * (int)len.value()) / 100;
+                       return (InsetCollapsable::getMaxWidth(bv, inset) * (int)width_.value()) / 100;
                default: 
                {
-                       int ww1 = VSpace(width_).inPixels(bv);
+                       int ww1 = width_.inPixels(bv);
                        int ww2 = InsetCollapsable::getMaxWidth(bv, inset);
                        if (ww2 > 0 && ww2 < ww1) {
                                return ww2;
index 8f07025fb493bfddaedbf73d3d090ae1f5ce3f99..b44524897ca6b3b8e3434f2aa69fec7d990b6e2f 100644 (file)
@@ -17,7 +17,7 @@
 #endif
 
 #include "insetcollapsable.h"
-#include "vspace.h"
+#include "lyxlength.h"
 #include <sigc++/signal_system.h>
 
 /** The minipage inset
@@ -71,13 +71,13 @@ public:
        ///
        void innerPos(InnerPosition);
        ///
-       string const & pageHeight() const;
+       LyXLength const & pageHeight() const;
        ///
-       void pageHeight(string const &);
+       void pageHeight(LyXLength const &);
        ///
-       string const & pageWidth() const;
+       LyXLength const & pageWidth() const;
        ///
-       void pageWidth(string const &);
+       void pageWidth(LyXLength const &);
        ///
        SigC::Signal0<void> hideDialog;
        ///
@@ -93,9 +93,9 @@ private:
        ///
        InnerPosition inner_pos_;
        ///
-       string height_;
+       LyXLength height_;
        ///
-       string width_;
+       LyXLength width_;
 };
 
 #endif
index 0990b8db484c49ab2eab973689a70ebd051bc865..0478b2020a629e9fd0ecbc951abf4153662b14b6 100644 (file)
@@ -2115,10 +2115,7 @@ int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
        
        if (len.zero())
                return -1;
-#ifdef WITH_WARNINGS
-#warning Remove use of VSpace as soon as LyXLength::inPixels exists (JMarc)
-#endif
-       return VSpace(len).inPixels(bv);
+       return len.inPixels(bv);
 }
 
 
index c1e08dd4448746a8036f8495098470712d3a351c..2cc2e853b2cc3b5720e74a9b23518849a79c23e7 100644 (file)
@@ -16,6 +16,9 @@
 
 #include "lyxlength.h"
 #include "lengthcommon.h"
+#include "lyxrc.h"
+#include "BufferView.h"
+#include "lyxtext.h"
 
 #include "Lsstream.h"
 
@@ -108,6 +111,98 @@ bool LyXLength::zero() const
 }
 
 
+int LyXLength::inPixels(BufferView const * bv) const
+{
+       // Height of a normal line in pixels (zoom factor considered)
+       int height = bv->text->defaultHeight(); // [pixels]
+       int default_width  = bv->workWidth();
+
+       // Zoom factor specified by user in percent
+       double const zoom = lyxrc.zoom / 100.0; // [percent]
+
+       // DPI setting for monitor: pixels/inch
+       double const dpi = lyxrc.dpi; // screen resolution [pixels/inch]
+
+       // Pixel values are scaled so that the ratio
+       // between lengths and font sizes on the screen
+       // is the same as on paper.
+
+       // we don't care about sign of value, we
+       // display negative space with text too
+       double result = 0.0;
+       int val_sign = val_ < 0.0 ? -1 : 1;
+               
+       switch (unit_) {
+       case LyXLength::SP:
+               // Scaled point: sp = 1/65536 pt
+               result = zoom * dpi * val_
+                       / (72.27 * 65536); // 4736286.7
+               break;
+       case LyXLength::PT:
+               // Point: 1 pt = 1/72.27 inch
+               result = zoom * dpi * val_
+                       / 72.27; // 72.27
+               break;
+       case LyXLength::BP:
+               // Big point: 1 bp = 1/72 inch
+               result = zoom * dpi * val_
+                       / 72; // 72
+               break;
+       case LyXLength::DD:
+               // Didot: 1157dd = 1238 pt?
+               result = zoom * dpi * val_
+                       / (72.27 / (0.376 * 2.845)); // 67.559735
+               break;
+       case LyXLength::MM:
+               // Millimeter: 1 mm = 1/25.4 inch
+               result = zoom * dpi * val_
+                       / 25.4; // 25.4
+               break;
+       case LyXLength::PC:
+               // Pica: 1 pc = 12 pt
+               result = zoom * dpi * val_
+                       / (72.27 / 12); // 6.0225
+               break;
+       case LyXLength::CC:
+               // Cicero: 1 cc = 12 dd
+               result = zoom * dpi * val_
+                       / (72.27 / (12 * 0.376 * 2.845)); // 5.6299779
+               break;
+       case LyXLength::CM:
+               // Centimeter: 1 cm = 1/2.54 inch
+               result = zoom * dpi * val_
+                       / 2.54; // 2.54
+               break;
+       case LyXLength::IN:
+               // Inch
+               result = zoom * dpi * val_;
+               break;
+       case LyXLength::EX:
+               // Ex: The height of an "x"
+               result = zoom * val_ * height / 2; // what to / width?
+               break;
+       case LyXLength::EM: // what to / width?
+               // Em: The width of an "m"
+               result = zoom * val_ * height / 2; // Why 2?
+               break;
+       case LyXLength::MU: // This is probably only allowed in
+               // math mode
+               result = zoom * val_ * height;
+               break;
+       case LyXLength::PW: // Always % of workarea
+       case LyXLength::PE:
+       case LyXLength::PP:
+       case LyXLength::PL:
+               result = val_ * default_width / 100;
+               break;
+       case LyXLength::UNIT_NONE:
+               result = 0;  // this cannot happen
+               break;
+       }
+       return static_cast<int>(result * val_sign + 0.5);
+}
+
+
 bool operator==(LyXLength const & l1, LyXLength const & l2)
 {
        return l1.value() == l2.value() && l1.unit() == l2.unit();
index 8b75cb62ff71a7668242d52ca5458619a58a486b..caba9ee171ab2f2ce14f222dae5347871defc8b4 100644 (file)
@@ -18,6 +18,8 @@
 
 #include "LString.h"
 
+class BufferView;
+
 //
 ///  LyXLength Class
 //
@@ -83,6 +85,8 @@ public:
        string const asString() const;
        ///
        string const asLatexString() const;
+       ///
+       int inPixels(BufferView const * bv) const;
 
        /** If "data" is valid, the length represented by it is
          stored into "result", if that is not 0. */
index ec023d85776312692686a1e4350040271641ece7..ae5cc6438df2672052a6a2a531bb9367ac072fac 100644 (file)
@@ -468,84 +468,7 @@ int VSpace::inPixels(BufferView * bv) const
        case VFILL:     return 3 * height;
                // leave space for the vfill symbol
        case LENGTH:
-               // Pixel values are scaled so that the ratio
-               // between lengths and font sizes on the screen
-               // is the same as on paper.
-
-               // we don't care about sign of value, we
-               // display negative space with text too
-               result = 0.0;
-               value  = len_.len().value();
-               int val_sign = value < 0.0 ? -1 : 1;
-               
-               switch (len_.len().unit()) {
-               case LyXLength::SP:
-                       // Scaled point: sp = 1/65536 pt
-                       result = zoom * dpi * value
-                               / (72.27 * 65536); // 4736286.7
-                       break;
-               case LyXLength::PT:
-                       // Point: 1 pt = 1/72.27 inch
-                       result = zoom * dpi * value
-                               / 72.27; // 72.27
-                       break;
-               case LyXLength::BP:
-                       // Big point: 1 bp = 1/72 inch
-                       result = zoom * dpi * value
-                               / 72; // 72
-                       break;
-               case LyXLength::DD:
-                       // Didot: 1157dd = 1238 pt?
-                       result = zoom * dpi * value
-                               / (72.27 / (0.376 * 2.845)); // 67.559735
-                       break;
-               case LyXLength::MM:
-                       // Millimeter: 1 mm = 1/25.4 inch
-                       result = zoom * dpi * value
-                               / 25.4; // 25.4
-                       break;
-               case LyXLength::PC:
-                       // Pica: 1 pc = 12 pt
-                       result = zoom * dpi * value
-                               / (72.27 / 12); // 6.0225
-                       break;
-               case LyXLength::CC:
-                       // Cicero: 1 cc = 12 dd
-                       result = zoom * dpi * value
-                               / (72.27 / (12 * 0.376 * 2.845)); // 5.6299779
-                       break;
-               case LyXLength::CM:
-                       // Centimeter: 1 cm = 1/2.54 inch
-                       result = zoom * dpi * value
-                               / 2.54; // 2.54
-                       break;
-               case LyXLength::IN:
-                       // Inch
-                       result = zoom * dpi * value;
-                       break;
-               case LyXLength::EX:
-                       // Ex: The height of an "x"
-                       result = zoom * value * height / 2; // what to / width?
-                       break;
-               case LyXLength::EM: // what to / width?
-                       // Em: The width of an "m"
-                       result = zoom * value * height / 2; // Why 2?
-                       break;
-               case LyXLength::MU: // This is probably only allowed in
-                       // math mode
-                       result = zoom * value * height;
-                       break;
-               case LyXLength::PW: // Always % of workarea
-               case LyXLength::PE:
-               case LyXLength::PP:
-               case LyXLength::PL:
-                       result = value * default_width / 100;
-                       break;
-               case LyXLength::UNIT_NONE:
-                       result = 0;  // this cannot happen
-                       break;
-               }
-               return static_cast<int>(result * val_sign + 0.5);
+               return len_.len().inPixels(bv);
        }
        return 0; // never reached
 }