/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* $Id$ */

package org.apache.fop.layoutmgr.inline;

import org.apache.fop.area.inline.InlineArea;
import org.apache.fop.area.Block;
import org.apache.fop.fo.flow.Wrapper;
import org.apache.fop.layoutmgr.BlockLayoutManager;
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
import org.apache.fop.layoutmgr.KnuthBox;
import org.apache.fop.layoutmgr.KnuthSequence;
import org.apache.fop.layoutmgr.LayoutContext;
import org.apache.fop.layoutmgr.ListElement;
import org.apache.fop.layoutmgr.PositionIterator;
import org.apache.fop.layoutmgr.TraitSetter;

import java.util.LinkedList;
import java.util.List;

/**
 * This is the layout manager for the fo:wrapper formatting object.
 */
public class WrapperLayoutManager extends LeafNodeLayoutManager {

    /**
     * Creates a new LM for fo:wrapper.
     * @param node the fo:wrapper
     */
    public WrapperLayoutManager(Wrapper node) {
        super(node);
    }

    /** {@inheritDoc} */
    @Override
    public InlineArea get(LayoutContext context) {
        // Create a zero-width, zero-height dummy area so this node can
        // participate in the ID handling. Otherwise, addId() wouldn't
        // be called. The area must also be added to the tree, because
        // determination of the X,Y position is done in the renderer.
        InlineArea area = new InlineArea();
        if (fobj.hasId()) {
            TraitSetter.setProducerID(area, fobj.getId());
        }
        return area;
    }

    /**
     * Overridden to generate a proper {@link ListElement}, if the parent
     * requires it (i.e. is a block-container, list-item-body...)
     * If the parent is a block, the line LM will take care of properly
     * wrapping the sequence in a line box.
     * {@inheritDoc}
     */
    @Override
    public List getNextKnuthElements(LayoutContext context, int alignment) {
        List returnList = super.getNextKnuthElements(context, alignment);
        KnuthSequence seq = (KnuthSequence) returnList.get(0);
        ListElement tempElement = (ListElement) seq.get(0);
        if (parentLayoutManager instanceof BlockStackingLayoutManager
                && !(parentLayoutManager instanceof BlockLayoutManager)) {
            // replace inline box with a block box
            returnList = new LinkedList();
            KnuthBox auxiliaryBox = new KnuthBox(0, tempElement.getPosition(), true);
            returnList.add(auxiliaryBox);
        } else {
            // make sure the inline box is an auxiliary one
            seq.set(0, new KnuthInlineBox(0, null, tempElement.getPosition(), true));
        }
        return returnList;
    }

    /**
     * Add the area for this layout manager.
     * This adds the dummy area to the parent, *if* it has an id
     * - otherwise it serves no purpose.
     * {@inheritDoc}
     */
    @Override
    public void addAreas(PositionIterator posIter, LayoutContext context) {
        if (fobj.hasId()) {
            addId();
            if (parentLayoutManager instanceof BlockStackingLayoutManager
                    && !(parentLayoutManager instanceof BlockLayoutManager)) {
                Block helperBlock = new Block();
                TraitSetter.setProducerID(helperBlock, fobj.getId());
                parentLayoutManager.addChildArea(helperBlock);
            } else {
                InlineArea area = getEffectiveArea();
                parentLayoutManager.addChildArea(area);
            }
        }
        while (posIter.hasNext()) {
            posIter.next();
        }
    }

    /** {@inheritDoc} */
    protected void addId() {
        getPSLM().addIDToPage(fobj.getId());
    }

}

@@ -1118,154 +1118,20 @@
 mgr.
-KnuthBox;%0Aimport org.apache.fop.layoutmgr.KnuthSequence;%0Aimport org.apache.fop.layoutmgr.LayoutContext;%0Aimport org.apache.fop.layoutmgr.ListElemen
+LayoutContex
 t;%0Ai
@@ -1229,61 +1229,8 @@
 r;%0A%0A
-import java.util.LinkedList;%0Aimport java.util.List;%0A%0A
 /**%0A
@@ -1555,38 +1555,24 @@
 eritDoc%7D */%0A
-    @Override%0A
     public I
@@ -2067,1163 +2067,8 @@
  %7D%0A%0A
-    /**%0A     * Overridden to generate a proper %7B@link ListElement%7D, if the parent%0A     * requires it (i.e. is a block-container, list-item-body...)%0A     * If the parent is a block, the line LM will take care of properly%0A     * wrapping the sequence in a line box.%0A     * %7B@inheritDoc%7D%0A     */%0A    @Override%0A    public List getNextKnuthElements(LayoutContext context, int alignment) %7B%0A        List returnList = super.getNextKnuthElements(context, alignment);%0A        KnuthSequence seq = (KnuthSequence) returnList.get(0);%0A        ListElement tempElement = (ListElement) seq.get(0);%0A        if (parentLayoutManager instanceof BlockStackingLayoutManager%0A                && !(parentLayoutManager instanceof BlockLayoutManager)) %7B%0A            // replace inline box with a block box%0A            returnList = new LinkedList();%0A            KnuthBox auxiliaryBox = new KnuthBox(0, tempElement.getPosition(), true);%0A            returnList.add(auxiliaryBox);%0A        %7D else %7B%0A            // make sure the inline box is an auxiliary one%0A            seq.set(0, new KnuthInlineBox(0, null, tempElement.getPosition(), true));%0A        %7D%0A        return returnList;%0A    %7D%0A%0A
     
@@ -2232,44 +2232,121 @@
    *
- %7B@inheritDoc%7D%0A     */%0A    @Override
+%0A     * @param posIter the position iterator%0A     * @param context the layout context for adding the area%0A     */
 %0A   

Revert previous commit; wrong class...