001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hslf.model;
019:
020: import org.apache.poi.ddf.*;
021: import org.apache.poi.hslf.record.OEPlaceholderAtom;
022: import org.apache.poi.hslf.exceptions.HSLFException;
023:
024: import java.util.List;
025: import java.io.ByteArrayOutputStream;
026:
027: /**
028: * Represents a Placeholder in PowerPoint.
029: *
030: * @author Yegor Kozlov
031: */
032: public class Placeholder extends TextBox {
033:
034: protected Placeholder(EscherContainerRecord escherRecord,
035: Shape parent) {
036: super (escherRecord, parent);
037: }
038:
039: public Placeholder(Shape parent) {
040: super (parent);
041: }
042:
043: public Placeholder() {
044: super ();
045: }
046:
047: /**
048: * Create a new Placeholder and initialize internal structures
049: *
050: * @return the created <code>EscherContainerRecord</code> which holds shape data
051: */
052: protected EscherContainerRecord createSpContainer(boolean isChild) {
053: EscherContainerRecord spcont = super .createSpContainer(isChild);
054:
055: EscherSpRecord spRecord = spcont
056: .getChildById(EscherSpRecord.RECORD_ID);
057: spRecord.setFlags(EscherSpRecord.FLAG_HAVEANCHOR
058: | EscherSpRecord.FLAG_HAVEMASTER);
059:
060: EscherClientDataRecord cldata = new EscherClientDataRecord();
061: cldata.setOptions((short) 15);
062:
063: EscherOptRecord opt = (EscherOptRecord) getEscherChild(spcont,
064: EscherOptRecord.RECORD_ID);
065:
066: //Placeholders can't be grouped
067: setEscherProperty(opt,
068: EscherProperties.PROTECTION__LOCKAGAINSTGROUPING,
069: 262144);
070:
071: //OEPlaceholderAtom tells powerpoint that this shape is a placeholder
072: //
073: OEPlaceholderAtom oep = new OEPlaceholderAtom();
074: /**
075: * Extarct from MSDN:
076: *
077: * There is a special case when the placeholder does not have a position in the layout.
078: * This occurs when the user has moved the placeholder from its original position.
079: * In this case the placeholder ID is -1.
080: */
081: oep.setPlacementId(-1);
082:
083: oep.setPlaceholderId(OEPlaceholderAtom.Body);
084:
085: //convert hslf into ddf record
086: ByteArrayOutputStream out = new ByteArrayOutputStream();
087: try {
088: oep.writeOut(out);
089: } catch (Exception e) {
090: throw new HSLFException(e);
091: }
092: cldata.setRemainingData(out.toByteArray());
093:
094: //append placeholder container before EscherTextboxRecord
095: List lst = spcont.getChildRecords();
096: for (int i = 0; i < lst.size(); i++) {
097: EscherRecord rec = (EscherRecord) lst.get(i);
098: if (rec.getRecordId() == EscherTextboxRecord.RECORD_ID) {
099: lst.add(i++, cldata);
100: }
101: }
102:
103: return spcont;
104: }
105: }
|