use of org.apache.poi.hslf.record.HSLFEscherClientDataRecord in project poi by apache.
the class HSLFHyperlink method find.
/**
* Find hyperlink assigned to the supplied shape
*
* @param shape <code>Shape</code> to lookup hyperlink in
* @return found hyperlink or <code>null</code>
*/
@SuppressWarnings("resource")
protected static HSLFHyperlink find(HSLFShape shape) {
HSLFSlideShow ppt = shape.getSheet().getSlideShow();
//document-level container which stores info about all links in a presentation
ExObjList exobj = ppt.getDocumentRecord().getExObjList(false);
HSLFEscherClientDataRecord cldata = shape.getClientData(false);
if (exobj != null && cldata != null) {
List<HSLFHyperlink> lst = new ArrayList<HSLFHyperlink>();
find(cldata.getHSLFChildRecords(), exobj, lst);
return lst.isEmpty() ? null : (HSLFHyperlink) lst.get(0);
}
return null;
}
use of org.apache.poi.hslf.record.HSLFEscherClientDataRecord in project poi by apache.
the class HSLFSimpleShape method setPlaceholder.
@Override
public void setPlaceholder(Placeholder placeholder) {
EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
int flags = spRecord.getFlags();
if (placeholder == null) {
flags ^= EscherSpRecord.FLAG_HAVEMASTER;
} else {
flags |= EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HAVEMASTER;
}
spRecord.setFlags(flags);
// Placeholders can't be grouped
setEscherProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, (placeholder == null ? -1 : 262144));
HSLFEscherClientDataRecord clientData = getClientData(false);
if (placeholder == null) {
if (clientData != null) {
clientData.removeChild(OEPlaceholderAtom.class);
clientData.removeChild(RoundTripHFPlaceholder12.class);
// remove client data if the placeholder was the only child to be carried
if (clientData.getChildRecords().isEmpty()) {
getSpContainer().removeChildRecord(clientData);
}
}
return;
}
if (clientData == null) {
clientData = getClientData(true);
}
// OEPlaceholderAtom tells powerpoint that this shape is a placeholder
OEPlaceholderAtom oep = null;
RoundTripHFPlaceholder12 rtp = null;
for (Record r : clientData.getHSLFChildRecords()) {
if (r instanceof OEPlaceholderAtom) {
oep = (OEPlaceholderAtom) r;
break;
}
if (r instanceof RoundTripHFPlaceholder12) {
rtp = (RoundTripHFPlaceholder12) r;
break;
}
}
/**
* Extract 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.
*/
byte phId;
HSLFSheet sheet = getSheet();
// TODO: implement/switch NotesMaster
if (sheet instanceof HSLFSlideMaster) {
phId = (byte) placeholder.nativeSlideMasterId;
} else if (sheet instanceof HSLFNotes) {
phId = (byte) placeholder.nativeNotesId;
} else {
phId = (byte) placeholder.nativeSlideId;
}
if (phId == -2) {
throw new HSLFException("Placeholder " + placeholder.name() + " not supported for this sheet type (" + sheet.getClass() + ")");
}
switch(placeholder) {
case HEADER:
case FOOTER:
if (rtp == null) {
rtp = new RoundTripHFPlaceholder12();
rtp.setPlaceholderId(phId);
clientData.addChild(rtp);
}
if (oep != null) {
clientData.removeChild(OEPlaceholderAtom.class);
}
break;
default:
if (rtp != null) {
clientData.removeChild(RoundTripHFPlaceholder12.class);
}
if (oep == null) {
oep = new OEPlaceholderAtom();
oep.setPlaceholderSize((byte) OEPlaceholderAtom.PLACEHOLDER_FULLSIZE);
// TODO: placement id only "SHOULD" be unique ... check other placeholders on sheet for unique id
oep.setPlacementId(-1);
oep.setPlaceholderId(phId);
clientData.addChild(oep);
}
break;
}
}
Aggregations