FileDocCategorySizeDatePackage
Placeholder.javaAPI DocApache Poi 3.0.13568Thu May 31 18:45:28 BST 2007org.apache.poi.hslf.model

Placeholder

public class Placeholder extends TextBox
Represents a Placeholder in PowerPoint.
author
Yegor Kozlov

Fields Summary
Constructors Summary
protected Placeholder(EscherContainerRecord escherRecord, Shape parent)

        super(escherRecord, parent);
    
public Placeholder(Shape parent)

        super(parent);
    
public Placeholder()

        super();
    
Methods Summary
protected org.apache.poi.ddf.EscherContainerRecordcreateSpContainer(boolean isChild)
Create a new Placeholder and initialize internal structures

return
the created EscherContainerRecord which holds shape data

        EscherContainerRecord spcont = super.createSpContainer(isChild);

        EscherSpRecord spRecord = spcont.getChildById(EscherSpRecord.RECORD_ID);
        spRecord.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HAVEMASTER);

        EscherClientDataRecord cldata = new EscherClientDataRecord();
        cldata.setOptions((short)15);

        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);

        //Placeholders can't be grouped
        setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 262144);

        //OEPlaceholderAtom tells powerpoint that this shape is a placeholder
        //
        OEPlaceholderAtom oep = new OEPlaceholderAtom();
        /**
         * Extarct from MSDN:
         *
         * There is a special case when the placeholder does not have a position in the layout.
         * This occurs when the user has moved the placeholder from its original position.
         * In this case the placeholder ID is -1.
         */
        oep.setPlacementId(-1);

        oep.setPlaceholderId(OEPlaceholderAtom.Body);

        //convert hslf into ddf record
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            oep.writeOut(out);
        } catch(Exception e){
            throw new HSLFException(e);
        }
        cldata.setRemainingData(out.toByteArray());

        //append placeholder container before EscherTextboxRecord
        List lst = spcont.getChildRecords();
        for (int i = 0; i < lst.size(); i++) {
              EscherRecord rec = (EscherRecord)lst.get(i);
              if(rec.getRecordId() == EscherTextboxRecord.RECORD_ID){
                  lst.add(i++, cldata);
              }
        }

        return spcont;