]> git.lyx.org Git - features.git/blobdiff - src/insets/InsetFloat.cpp
Completion: handle undo in insets' insertCompletion methods
[features.git] / src / insets / InsetFloat.cpp
index fc82d5cfc5519b3851ba82b49979fb67d497a3fc..0c9f3d48c57617442af3d266ce841ea147e213f7 100644 (file)
@@ -759,8 +759,7 @@ void docbookGenerateFillerTable(XMLStream & xs, BufferParams::TableOutput format
 
 
 void docbookNoSubfigures(XMLStream & xs, OutputParams const & runparams, const InsetCaption * caption,
-                         const InsetLabel * label, Floating const & ftype, const InsetFloat * thisFloat)
-{
+                         const InsetLabel * label, Floating const & ftype, const InsetFloat * thisFloat) {
        // Ensure there is no label output, it is supposed to be handled as xml:id.
        OutputParams rpNoLabel = runparams;
        if (label)
@@ -775,17 +774,26 @@ void docbookNoSubfigures(XMLStream & xs, OutputParams const & runparams, const I
 
        // Generate the contents of the float (to check for emptiness).
        odocstringstream osFloatContent;
-       XMLStream xsFloatContent(osFloatContent);
-       thisFloat->InsetText::docbook(xsFloatContent, rpNoTitle);
-       bool hasFloat = !osFloatContent.str().empty();
+       bool hasFloat = false;
+
+       if (thisFloat) {
+               XMLStream xsFloatContent(osFloatContent);
+               thisFloat->InsetText::docbook(xsFloatContent, rpNoTitle);
+               hasFloat = !osFloatContent.str().empty();
+       }
 
        // Do the same for the caption.
        odocstringstream osCaptionContent;
-       XMLStream xsCaptionContent(osCaptionContent);
-       caption->getCaptionAsDocBook(xsCaptionContent, rpNoLabel);
-       bool hasCaption = !osCaptionContent.str().empty();
+       bool hasCaption = false;
 
-       // Organisation: <float> <title if any/> <contents without title/> </float>.
+       if (caption != nullptr) {
+               XMLStream xsCaptionContent(osCaptionContent);
+               caption->getCaptionAsDocBook(xsCaptionContent, rpNoLabel);
+               hasCaption = !osCaptionContent.str().empty();
+       }
+
+       // Organisation: <float with xml:id if any> <title if any/> <contents without title nor xml:id/> </float>.
+       // Titles and xml:id are generated with specific insets and must be dealt with using OutputParams.
 
        // - Generate the attributes for the float tag.
        docstring attr = docstring();
@@ -811,12 +819,15 @@ void docbookNoSubfigures(XMLStream & xs, OutputParams const & runparams, const I
        }
 
        // - Output the actual content of the float or some dummy content (to ensure that the output
-       // document is valid).
+       // document is valid). Use HTML tables by default, unless an InsetFloat is given.
        if (hasFloat)
                xs << XMLStream::ESCAPE_NONE << osFloatContent.str();
-       else if (ftype.docbookFloatType() == "table")
-               docbookGenerateFillerTable(xs, thisFloat->buffer().params().docbook_table_output);
-       else
+       else if (ftype.docbookFloatType() == "table") {
+               BufferParams::TableOutput tableFormat = BufferParams::HTMLTable;
+               if (thisFloat)
+                       tableFormat = thisFloat->buffer().params().docbook_table_output;
+               docbookGenerateFillerTable(xs, tableFormat);
+       } else
                docbookGenerateFillerMedia(xs);
 
        // - Close the float.
@@ -868,12 +879,21 @@ bool InsetFloat::insetAllowed(InsetCode code) const
 }
 
 
+void InsetFloat::updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted)
+{
+       InsetCaptionable::updateBuffer(it, utype, deleted);
+       bool const subflt = (it.innerInsetOfType(FLOAT_CODE)
+                            || it.innerInsetOfType(WRAP_CODE));
+       setSubfloat(subflt);
+}
+
+
 void InsetFloat::setWide(bool w, bool update_label)
 {
        if (!buffer().params().documentClass().floats().allowsWide(params_.type))
                params_.wide = false;
        else
-           params_.wide = w;
+               params_.wide = w;
        if (update_label)
                setNewLabel();
 }