Michael Gerz wrote:
Jean-Marc Lasgouttes schrieb:
Other than that, I am not sure that I like all this automatic
centering business. If the user has already provided some contents, it
is very surprising that inserting a float around it would modify its
alignment.
JMarc

JMarc, Bernhard,

I committed a slightly modified patch that fixes the reported bug (see below). It should be pretty simple to include the centering feature such that it does not modify existing paragraphs - once we know how to do that in a technically safe way.

Michael

Hello,

A few words to this patch:

* This patch adds the method Paragraph::setAlign as you, JMarc, assumed. Here i assumed that the expression (layout->align & layout->alignpossible) is always true, is that correct?

* This method is used to center the paragraph above and below the caption inset if no text was selected when creating the inset.

* The the method Paragraph::getAlign returned a char and not the enum LyXAlignment as defined in layout.h. Since layout.h is very short and does not include any other file i included it in paragraph.h and changed the return type of Paragraph::getAlign to LyXAlignment.

Bernhard
Index: src/paragraph.C
===================================================================
--- src/paragraph.C     (revision 17140)
+++ src/paragraph.C     (working copy)
@@ -601,8 +601,17 @@
 }
 
 
-char Paragraph::getAlign() const
+void Paragraph::setAlign(LyXAlignment align)
 {
+       if (align == LYX_ALIGN_LAYOUT || align == layout()->align)
+               params().align(LYX_ALIGN_LAYOUT);
+       else if (align & layout()->alignpossible)
+               params().align(align);
+}
+
+
+LyXAlignment Paragraph::getAlign() const
+{
        if (params().align() == LYX_ALIGN_LAYOUT)
                return layout()->align;
        else
Index: src/paragraph.h
===================================================================
--- src/paragraph.h     (revision 17140)
+++ src/paragraph.h     (working copy)
@@ -21,6 +21,7 @@
 #include "InsetList.h"
 #include "lyxlayout_ptr_fwd.h"
 #include "RowList_fwd.h"
+#include "layout.h"
 
 #include "insets/insetbase.h" // only for InsetBase::Code
 
@@ -237,7 +238,10 @@
        docstring expandLabel(LyXLayout_ptr const &, BufferParams const &,
                bool process_appendix = true) const;
        /// Actual paragraph alignment used
-       char getAlign() const;
+       LyXAlignment getAlign() const;
+       /// Set the paragraph alignment if it is allowed by the layout
+       void setAlign(LyXAlignment align);
+
        /// The nesting depth of a paragraph
        depth_type getDepth() const;
        /// The maximal possible depth of a paragraph after this one
Index: src/text2.C
===================================================================
--- src/text2.C (revision 17140)
+++ src/text2.C (working copy)
@@ -604,18 +604,7 @@
                Paragraph & par = pars_[pit];
                ParagraphParameters & params = par.params();
                params.spacing(spacing);
-
-               // does the layout allow the new alignment?
-               LyXLayout_ptr const & layout = par.layout();
-
-               if (align == LYX_ALIGN_LAYOUT)
-                       align = layout->align;
-               if (align & layout->alignpossible) {
-                       if (align == layout->align)
-                               params.align(LYX_ALIGN_LAYOUT);
-                       else
-                               params.align(align);
-               }
+               par.setAlign(align);
                par.setLabelWidthString(labelwidthstring);
                params.noindent(noindent);
        }
Index: src/text3.C
===================================================================
--- src/text3.C (revision 17140)
+++ src/text3.C (working copy)
@@ -1229,10 +1229,11 @@
                // paragraph at the bottom so that the user can choose where to 
put
                // the graphics (or table).
                if (!content) {
+                       pars[0].setAlign(LYX_ALIGN_CENTER);
                        pars.push_back(Paragraph());
                        pars.back().setInsetOwner(pars[0].inInset());
                        pars.back().layout(tclass.defaultLayout());
-                       
+                       pars.back().setAlign(LYX_ALIGN_CENTER);
                }
 
                // reposition the cursor to the caption

Reply via email to