]> git.lyx.org Git - features.git/commitdiff
- new support for makebox; fileformat change
authorUwe Stöhr <uwestoehr@web.de>
Sat, 3 Jul 2010 13:14:15 +0000 (13:14 +0000)
committerUwe Stöhr <uwestoehr@web.de>
Sat, 3 Jul 2010 13:14:15 +0000 (13:14 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34748 a592a061-630c-0410-9148-cb99ea01b6c8

development/FORMAT
lib/lyx2lyx/lyx_2_0.py
src/Buffer.cpp
src/frontends/qt4/GuiBox.cpp
src/insets/InsetBox.cpp
src/insets/InsetBox.h

index 144a12fc58cb7d3717464de828b73db0af123509..47a0c33108d5b805ea3319fa0b221b8b99f9027e 100644 (file)
@@ -7,6 +7,10 @@ The good example would be 2010-01-10 entry.
 
 -----------------------
 
+2010-07-03 Uwe Stöhr <uwestoehr@web.de>
+       * Format incremented to 394: support for makebox;
+         new box parameter \use_makebox
+
 2010-06-07 Richard Heck <rgheck@comcast.net>
        * Format incremented to 393 (r34619)
                Renaming in LyX format: \begin_inset OptArg becomes
index 0deb737c2fb97802d1e0890eec12bc4b1afa07d5..742f50e5f65d9198295fb6b0ea73d5f69c336daf 100644 (file)
@@ -1717,7 +1717,44 @@ def revert_argument(document):
       return
       document.body[i] = "\\begin_inset OptArg"
       i += 1
-      
+
+
+def revert_makebox(document):
+  " Convert \\makebox to ERT "
+  i = 0
+  while 1:
+    # only revert frameless boxes without an inner box
+    i = find_token(document.body, '\\begin_inset Box Frameless', i)
+    if i == -1:
+      return
+    else:
+      z = find_end_of_inset(document.body, i)
+      if z == -1:
+        document.warning("Malformed LyX document: Can't find end of box inset.")
+        return
+      j = find_token(document.body, 'use_makebox 1', i)
+      # assure we found the makebox of the current box
+      if j > i + 7 or j == -1:
+       return
+      else:
+        # remove the \end_inset
+        document.body[z - 2:z + 1] = put_cmd_in_ert("}")
+        # determine the alignment
+        k = find_token(document.body, 'hor_pos', j - 4)
+        align = document.body[k][9]
+        # determine the width
+        l = find_token(document.body, 'width "', j + 1)
+        length = document.body[l][7:]
+        # remove trailing '"'
+        length = length[:-1]
+        # latex_length returns "bool,length"
+        length = latex_length(length).split(",")[1]
+        subst = "\\makebox[" + length + "][" \
+         + align + "]{"
+        document.body[i:i+13] = put_cmd_in_ert(subst)
+    i += 1
+
+
 ##
 # Conversion hub
 #
@@ -1770,10 +1807,12 @@ convert = [[346, []],
            [390, []],
            [391, []],
            [392, [convert_beamer_args]],
-           [393, [convert_optarg]]
+           [393, [convert_optarg]],
+           [394, []]
           ]
 
-revert =  [[392, [revert_argument]],
+revert =  [[393, [revert_makebox]],
+           [392, [revert_argument]],
            [391, [revert_beamer_args]],
            [390, [revert_align_decimal]],
            [389, [revert_output_sync]],
index bb4fe6e4b02565f7ce93d9d4dc332071611f5cfc..fd483fa64bba02b26eddbc7b8da653d4da3761ba 100644 (file)
@@ -126,7 +126,7 @@ namespace {
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-int const LYX_FORMAT = 393; // rgh: rename OptArg to Argument in LyX format
+int const LYX_FORMAT = 394; // uwestoehr: support for \makebox
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
index 1e928ad54d31d6d10ddd6a7c6b8c278845263d53..a74117ef74897acbc6a9e1574b59857d17d91d40 100644 (file)
@@ -113,12 +113,18 @@ GuiBox::GuiBox(QWidget * parent) : InsetParamsWidget(parent)
 
 void GuiBox::on_innerBoxCO_activated(int index)
 {
+       QString itype =
+               innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
+       // handle parbox and minipage the same way
        bool const ibox =
-               (innerBoxCO->itemData(index).toString() != "none");
+               (itype != "none"
+                && itype != "makebox");
        QString const outer =
                typeCO->itemData(typeCO->currentIndex()).toString();
        valignCO->setEnabled(ibox);
        ialignCO->setEnabled(ibox);
+       if (heightCB->isChecked() && !ibox)
+               heightCB->setChecked(false);
        heightCB->setEnabled(ibox);
        // except for frameless and boxed, the width cannot be specified if
        // there is no inner box
@@ -126,8 +132,10 @@ void GuiBox::on_innerBoxCO_activated(int index)
                outer != "Boxed");
        widthED->setEnabled(!width_disabled);
        widthUnitsLC->setEnabled(!width_disabled);
-       // halign and pagebreak are only allowed for Boxed without inner box
-       halignCO->setEnabled(!ibox && outer == "Boxed");
+       // halign is only allowed for Boxed without inner box or for makebox
+       halignCO->setEnabled((!ibox && outer == "Boxed")
+               || (itype == "makebox"));
+       // pagebreak is only allowed for Boxed without inner box
        pagebreakCB->setEnabled(!ibox && outer == "Boxed");
        setSpecial(ibox);
        changed();
@@ -139,26 +147,34 @@ void GuiBox::on_typeCO_activated(int index)
        QString const type =
                typeCO->itemData(index).toString();
        bool const frameless = (type == "Frameless");
-       if (frameless) {
-               valignCO->setEnabled(true);
-               ialignCO->setEnabled(true);
-               heightCB->setEnabled(true);
-               setSpecial(true);
-       }
-       if (type != "Boxed")
-               pagebreakCB->setChecked(false);
        QString itype =
                innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
+       setInnerType(frameless, itype);
+       // refresh itype because it might have been changed in setInnerType
+       itype =
+               innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
+       // handle parbox and minipage the same way
+       bool const ibox =
+               (itype != "none"
+                && itype != "makebox");
+       if (frameless && itype != "makebox") {
+               valignCO->setEnabled(ibox);
+               ialignCO->setEnabled(ibox);
+               if (heightCB->isChecked() && !ibox)
+                       heightCB->setChecked(false);
+               heightCB->setEnabled(ibox);
+               setSpecial(ibox);
+       }
        // except for frameless and boxed, the width cannot be specified if
        // there is no inner box
        bool const width_disabled = (itype == "none" && !frameless
                && type != "Boxed");
        widthED->setEnabled(!width_disabled);
        widthUnitsLC->setEnabled(!width_disabled);
-       // halign and pagebreak are only allowed for Boxed without inner box
-       halignCO->setEnabled(type == "Boxed" && itype == "none");
+       // halign is only allowed for Boxed without inner box or for makebox
+       halignCO->setEnabled((type == "Boxed" && itype == "none") || (itype == "makebox"));
+       // pagebreak is only allowed for Boxed without inner box
        pagebreakCB->setEnabled(type == "Boxed" && itype == "none");
-       setInnerType(frameless, itype);
        changed();
 }
 
@@ -224,6 +240,8 @@ void GuiBox::paramsToDialog(Inset const * inset)
                inner_type = "none";
        if (params.use_parbox)
                inner_type = "parbox";
+       if (params.use_makebox)
+               inner_type = "makebox";
        bool const frameless = (params.type == "Frameless");
        setInnerType(frameless, inner_type);
 
@@ -234,13 +252,14 @@ void GuiBox::paramsToDialog(Inset const * inset)
        c = params.hor_pos;
        halignCO->setCurrentIndex(string("lcrs").find(c, 0));
 
-       bool ibox = params.inner_box;
+       bool ibox = (params.inner_box && !params.use_makebox);
        valignCO->setEnabled(ibox);
        ialignCO->setEnabled(ibox);
        setSpecial(ibox);
 
        // halign and pagebreak are only allowed for Boxed without inner box
-       halignCO->setEnabled(!ibox && type == "Boxed");
+       halignCO->setEnabled((!ibox && type == "Boxed") || (params.use_makebox));
+       // pagebreak is only allowed for Boxed without inner box
        pagebreakCB->setEnabled(!ibox && type == "Boxed");
 
        // except for frameless and boxed, the width cannot be specified if
@@ -294,6 +313,8 @@ docstring GuiBox::dialogToParams() const
                (!pagebreak && innerBoxCO->currentText() != qt_("None"));
        params.use_parbox =
                (!pagebreak && innerBoxCO->currentText() == qt_("Parbox"));
+       params.use_makebox =
+               (!pagebreak && innerBoxCO->currentText() == qt_("Makebox"));
 
        params.pos = "tcb"[valignCO->currentIndex()];
        params.inner_pos = "tcbs"[ialignCO->currentIndex()];
@@ -367,6 +388,8 @@ void GuiBox::setInnerType(bool frameless, QString const & type)
        innerBoxCO->clear();
        if (!frameless)
                innerBoxCO->addItem(qt_("None"), toqstr("none"));
+       else
+               innerBoxCO->addItem(qt_("Makebox"), toqstr("makebox"));
        innerBoxCO->addItem(qt_("Parbox"), toqstr("parbox"));
        innerBoxCO->addItem(qt_("Minipage"), toqstr("minipage"));
        int i = (innerBoxCO->findData(type) != -1)
index a4a2e606e58e94b9080c94b9a5b33b22d542f7de..832ab2dd9ea2fc818cbf80b69d706c9dcc757acb 100644 (file)
@@ -136,6 +136,8 @@ void InsetBox::setButtonLabel()
        if (params_.inner_box) {
                if (params_.use_parbox)
                        inner = _("Parbox");
+               else if (params_.use_makebox)
+                       inner = _("Makebox");
                else
                        inner = _("Minipage");
        }
@@ -294,7 +296,6 @@ int InsetBox::latex(odocstream & os, OutputParams const & runparams) const
                        if (params_.hor_pos != 'c')
                                os << "[" << params_.hor_pos << "]";
                }
-
                os << "{";
                break;
        case ovalbox:
@@ -317,38 +318,56 @@ int InsetBox::latex(odocstream & os, OutputParams const & runparams) const
        if (params_.inner_box) {
                if (params_.use_parbox)
                        os << "\\parbox";
+               else if (params_.use_makebox) {
+                       os << "\\makebox";
+                       // FIXME UNICODE
+                       // output the width and horizontal position
+                       if (params_.special != "none") {
+                               os << "[" << params_.width.value()
+                                  << '\\' << from_utf8(params_.special)
+                                  << ']';
+                       } else
+                               os << '[' << from_ascii(width_string)
+                                  << ']';
+                       if (params_.hor_pos != 'c')
+                               os << "[" << params_.hor_pos << "]";
+                       os << "{";
+               }
                else
                        os << "\\begin{minipage}";
 
-               os << "[" << params_.pos << "]";
-               if (params_.height_special == "none") {
-                       // FIXME UNICODE
-                       os << "[" << from_ascii(params_.height.asLatexString()) << "]";
-               } else {
-                       // Special heights
-                       // set no optional argument when the value is the default "1\height"
-                       // (special units like \height are handled as "in")
-                       // but when the user has chosen a non-default inner_pos, the height
-                       // must be given: \minipage[pos][height][inner-pos]{width}
-                       if ((params_.height != Length("1in") ||
-                                params_.height_special != "totalheight") ||
-                               params_.inner_pos != params_.pos) {
+               // output parameters for parbox and minipage
+               if (!params_.use_makebox) {
+                       os << "[" << params_.pos << "]";
+                       if (params_.height_special == "none") {
                                // FIXME UNICODE
-                               os << "[" << params_.height.value()
-                                       << "\\" << from_utf8(params_.height_special) << "]";
+                               os << "[" << from_ascii(params_.height.asLatexString()) << "]";
+                       } else {
+                               // Special heights
+                               // set no optional argument when the value is the default "1\height"
+                               // (special units like \height are handled as "in")
+                               // but when the user has chosen a non-default inner_pos, the height
+                               // must be given: \minipage[pos][height][inner-pos]{width}
+                               if ((params_.height != Length("1in") ||
+                                       params_.height_special != "totalheight") ||
+                                       params_.inner_pos != params_.pos) {
+                                               // FIXME UNICODE
+                                               os << "[" << params_.height.value()
+                                                       << "\\" << from_utf8(params_.height_special) << "]";
+                               }
                        }
+                       if (params_.inner_pos != params_.pos)
+                               os << "[" << params_.inner_pos << "]";
+                       // FIXME UNICODE
+                       os << '{' << from_ascii(width_string) << '}';
+                       if (params_.use_parbox)
+                               os << "{";
                }
-               if (params_.inner_pos != params_.pos)
-                       os << "[" << params_.inner_pos << "]";
-
-               // FIXME UNICODE
-               os << '{' << from_ascii(width_string) << '}';
 
-               if (params_.use_parbox)
-                       os << "{";
                os << "%\n";
                ++i;
-       }
+       } // end if inner_box
+
        if (btype == Shaded) {
                os << "\\begin{shaded}%\n";
                ++i;
@@ -360,7 +379,7 @@ int InsetBox::latex(odocstream & os, OutputParams const & runparams) const
                os << "\\end{shaded}";
 
        if (params_.inner_box) {
-               if (params_.use_parbox)
+               if (params_.use_parbox || params_.use_makebox)
                        os << "%\n}";
                else
                        os << "%\n\\end{minipage}";
@@ -564,6 +583,7 @@ void InsetBox::string2params(string const & in, InsetBoxParams & params)
 InsetBoxParams::InsetBoxParams(string const & label)
        : type(label),
          use_parbox(false),
+         use_makebox(false),
          inner_box(true),
          width(Length("100col%")),
          special("none"),
@@ -583,6 +603,7 @@ void InsetBoxParams::write(ostream & os) const
        os << "has_inner_box " << inner_box << "\n";
        os << "inner_pos \"" << inner_pos << "\"\n";
        os << "use_parbox " << use_parbox << "\n";
+       os << "use_makebox " << use_makebox << "\n";
        os << "width \"" << width.asString() << "\"\n";
        os << "special \"" << special << "\"\n";
        os << "height \"" << height.asString() << "\"\n";
@@ -601,6 +622,7 @@ void InsetBoxParams::read(Lexer & lex)
                inner_box = false;
        lex >> "inner_pos" >> inner_pos;
        lex >> "use_parbox" >> use_parbox;
+       lex >> "use_makebox" >> use_makebox;
        lex >> "width" >> width;
        lex >> "special" >> special;
        lex >> "height" >> height;
index 55d189294f452adb4d92c935c2e9adf3e78758e0..b0692484f5cb00eca7f28e36fc08ab574ed3a80d 100644 (file)
@@ -31,8 +31,10 @@ public:
 
        ///
        std::string type;
-       /// Use a parbox (true) or minipage (false)
+       /// Is there a parbox?
        bool use_parbox;
+       /// Is there a makebox?
+       bool use_makebox;
        /// Do we have an inner parbox or minipage to format paragraphs to
        /// columnwidth?
        bool inner_box;