--- /dev/null
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.hslf.record;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+\r
+import org.apache.poi.util.LittleEndian;\r
+import org.apache.poi.util.LittleEndianConsts;\r
+\r
+/**\r
+ * A SlideShowSlideInfo Atom (type 1017).<br/>\r
+ * <br/>\r
+ * \r
+ * An atom record that specifies which transition effects to perform\r
+ * during a slide show, and how to advance to the next presentation slide.<br/>\r
+ * <br/>\r
+ *\r
+ * Combination of effectType and effectDirection:\r
+ * <table>\r
+ * <tr><th>type</th><th>description</th><th>direction</th></tr>\r
+ * <tr><td>0</td><td>cut</td><td>0x00 = no transition, 0x01 = black transition</td></tr>\r
+ * <tr><td>1</td><td>random</td><td>0x00</td></tr>\r
+ * <tr><td>2</td><td>blinds</td><td>0x00 = vertical, 0x01 = horizontal</td></tr>\r
+ * <tr><td>3</td><td>checker</td><td>like blinds</td></tr>\r
+ * <tr><td>4</td><td>cover</td><td>0x00 = left, 0x01 = up, 0x02 = right, 0x03 = down, 0x04 = left/up, 0x05 = right/up, 0x06 left/down, 0x07 = left/down</td></tr>\r
+ * <tr><td>5</td><td>dissolve</td><td>0x00</td></tr>\r
+ * <tr><td>6</td><td>fade</td><td>0x00</td></tr>\r
+ * <tr><td>7</td><td>uncover</td><td>like cover</td></tr>\r
+ * <tr><td>8</td><td>random bars</td><td>like blinds</td></tr>\r
+ * <tr><td>9</td><td>strips</td><td>like 0x04 - 0x07 of cover</td></tr>\r
+ * <tr><td>10</td><td>wipe</td><td>like 0x00 - 0x03 of cover</td></tr>\r
+ * <tr><td>11</td><td>box in/out</td><td>0x00 = out, 0x01 = in</td></tr>\r
+ * <tr><td>13</td><td>split</td><td>0x00 = horizontally out, 0x01 = horizontally in, 0x02 = vertically out, 0x03 = vertically in</td></tr>\r
+ * <tr><td>17</td><td>diamond</td><td>0x00</td></tr>\r
+ * <tr><td>18</td><td>plus</td><td>0x00</td></tr>\r
+ * <tr><td>19</td><td>wedge</td><td>0x00</td></tr>\r
+ * <tr><td>20</td><td>push</td><td>like 0x00 - 0x03 of cover</td></tr>\r
+ * <tr><td>21</td><td>comb</td><td>like blinds</td></tr>\r
+ * <tr><td>22</td><td>newsflash</td><td>0x00</td></tr>\r
+ * <tr><td>23</td><td>alphafade</td><td>0x00</td></tr>\r
+ * <tr><td>26</td><td>wheel</td><td>number of radial divisions (0x01,0x02,0x03,0x04,0x08)</td></tr>\r
+ * <tr><td>27</td><td>circle</td><td>0x00</td></tr>\r
+ * <tr><td>255</td><td>undefined</td><td>0x00</td></tr>\r
+ * </table>\r
+ */\r
+public class SSSlideInfoAtom extends RecordAtom {\r
+ /**\r
+ * A bit that specifies whether the presentation slide can be\r
+ * manually advanced by the user during the slide show.\r
+ */\r
+ public static int MANUAL_ADVANCE_BIT = 1 << 0;\r
+ \r
+ /**\r
+ * A bit that specifies whether the corresponding slide is \r
+ * hidden and is not displayed during the slide show.\r
+ */\r
+ public static int HIDDEN_BIT = 1 << 2;\r
+ \r
+ /**\r
+ * A bit that specifies whether to play the sound specified by soundIfRef.\r
+ */\r
+ public static int SOUND_BIT = 1 << 4;\r
+ \r
+ /**\r
+ * A bit that specifies whether the sound specified by soundIdRef is\r
+ * looped continuously when playing until the next sound plays.\r
+ */\r
+ public static int LOOP_SOUND_BIT = 1 << 6;\r
+ \r
+ /**\r
+ * A bit that specifies whether to stop any currently playing \r
+ * sound when the transition starts.\r
+ */\r
+ public static int STOP_SOUND_BIT = 1 << 8;\r
+ \r
+ /**\r
+ * A bit that specifies whether the slide will automatically\r
+ * advance after slideTime milliseconds during the slide show.\r
+ */\r
+ public static int AUTO_ADVANCE_BIT = 1 << 10;\r
+\r
+ /**\r
+ * A bit that specifies whether to display the cursor during\r
+ * the slide show. \r
+ */\r
+ public static int CURSOR_VISIBLE_BIT = 1 << 12;\r
+ \r
+ // public static int RESERVED1_BIT = 1 << 1;\r
+ // public static int RESERVED2_BIT = 1 << 3;\r
+ // public static int RESERVED3_BIT = 1 << 5;\r
+ // public static int RESERVED4_BIT = 1 << 7;\r
+ // public static int RESERVED5_BIT = 1 << 9;\r
+ // public static int RESERVED6_BIT = 1 << 11;\r
+ // public static int RESERVED7_BIT = 1 << 13 | 1 << 14 | 1 << 15;\r
+ \r
+ private static long _type = RecordTypes.SSSlideInfoAtom.typeID;\r
+\r
+ private byte[] _header;\r
+\r
+ /**\r
+ * A signed integer that specifies an amount of time, in milliseconds, to wait\r
+ * before advancing to the next presentation slide. It MUST be greater than or equal to 0 and\r
+ * less than or equal to 86399000. It MUST be ignored unless AUTO_ADVANCE_BIT is TRUE.\r
+ */\r
+ private int _slideTime = 0;\r
+ \r
+ /**\r
+ * A SoundIdRef that specifies which sound to play when the transition starts. \r
+ */\r
+ private int _soundIdRef = 0;\r
+\r
+ /**\r
+ * A byte that specifies the variant of effectType. In combination of the effectType\r
+ * there are further restriction and specification of this field.\r
+ */\r
+ private short _effectDirection = 0; // byte\r
+ \r
+ /**\r
+ * A byte that specifies which transition is used when transitioning to the\r
+ * next presentation slide during a slide show. Exact rendering of any transition is \r
+ * determined by the rendering application. As such, the same transition can have\r
+ * many variations depending on the implementation.\r
+ */\r
+ private short _effectType = 0; // byte\r
+ \r
+ /**\r
+ * Various flags - see bitmask for more details\r
+ */\r
+ private short _effectTransitionFlags = 0;\r
+ \r
+ /**\r
+ * A byte value that specifies how long the transition takes to run.\r
+ * (0x00 = 0.75 seconds, 0x01 = 0.5 seconds, 0x02 = 0.25 seconds) \r
+ */\r
+ private short _speed = 0; // byte\r
+ private byte[] _unused; // 3-byte\r
+\r
+ public SSSlideInfoAtom() {\r
+ _header = new byte[8];\r
+ LittleEndian.putShort(_header, 0, (short)0);\r
+ LittleEndian.putShort(_header, 2, (short)_type);\r
+ LittleEndian.putShort(_header, 4, (short)0x10);\r
+ LittleEndian.putShort(_header, 6, (short)0);\r
+ _unused = new byte[3];\r
+ }\r
+ \r
+ public SSSlideInfoAtom(byte[] source, int offset, int len) {\r
+ int ofs = offset;\r
+\r
+ // Sanity Checking\r
+ if(len != 24) len = 24;\r
+ assert(source.length >= offset+len);\r
+ \r
+ // Get the header\r
+ _header = LittleEndian.getByteArray(source,ofs,8);\r
+ ofs += _header.length;\r
+ \r
+ assert(LittleEndian.getShort(_header, 0) == 0);\r
+ assert(LittleEndian.getShort(_header, 2) == RecordTypes.SSSlideInfoAtom.typeID);\r
+ assert(LittleEndian.getShort(_header, 4) == 0x10);\r
+ assert(LittleEndian.getShort(_header, 6) == 0);\r
+\r
+ _slideTime = LittleEndian.getInt(source, ofs);\r
+ assert(0 <= _slideTime && _slideTime <= 86399000);\r
+ ofs += LittleEndianConsts.INT_SIZE;\r
+ _soundIdRef = LittleEndian.getInt(source, ofs);\r
+ ofs += LittleEndianConsts.INT_SIZE;\r
+ _effectDirection = LittleEndian.getUByte(source, ofs);\r
+ ofs += LittleEndianConsts.BYTE_SIZE;\r
+ _effectType = LittleEndian.getUByte(source, ofs);\r
+ ofs += LittleEndianConsts.BYTE_SIZE;\r
+ _effectTransitionFlags = LittleEndian.getShort(source, ofs);\r
+ ofs += LittleEndianConsts.SHORT_SIZE;\r
+ _speed = LittleEndian.getUByte(source, ofs);\r
+ ofs += LittleEndianConsts.BYTE_SIZE;\r
+ _unused = LittleEndian.getByteArray(source,ofs,3);\r
+ }\r
+\r
+ /**\r
+ * Write the contents of the record back, so it can be written\r
+ * to disk\r
+ */\r
+ public void writeOut(OutputStream out) throws IOException {\r
+ // Header - size or type unchanged\r
+ out.write(_header);\r
+ writeLittleEndian(_slideTime, out);\r
+ writeLittleEndian(_soundIdRef, out);\r
+ \r
+ byte byteBuf[] = new byte[LittleEndianConsts.BYTE_SIZE];\r
+ LittleEndian.putUByte(byteBuf, 0, _effectDirection);\r
+ out.write(byteBuf);\r
+ LittleEndian.putUByte(byteBuf, 0, _effectType);\r
+ out.write(byteBuf);\r
+ \r
+ writeLittleEndian(_effectTransitionFlags, out);\r
+ LittleEndian.putUByte(byteBuf, 0, _speed);\r
+ out.write(byteBuf);\r
+\r
+ assert(_unused.length == 3);\r
+ out.write(_unused);\r
+ }\r
+ \r
+ /**\r
+ * We are of type 1017\r
+ */\r
+ public long getRecordType() { return _type; }\r
+\r
+\r
+ public int getSlideTime() {\r
+ return _slideTime;\r
+ }\r
+\r
+ public void setSlideTime(int slideTime) {\r
+ this._slideTime = slideTime;\r
+ }\r
+\r
+ public int getSoundIdRef() {\r
+ return _soundIdRef;\r
+ }\r
+\r
+ public void setSoundIdRef(int soundIdRef) {\r
+ this._soundIdRef = soundIdRef;\r
+ }\r
+\r
+ public short getEffectDirection() {\r
+ return _effectDirection;\r
+ }\r
+\r
+ public void setEffectDirection(short effectDirection) {\r
+ this._effectDirection = effectDirection;\r
+ }\r
+\r
+ public short getEffectType() {\r
+ return _effectType;\r
+ }\r
+\r
+ public void setEffectType(short effectType) {\r
+ this._effectType = effectType;\r
+ }\r
+\r
+ public short getEffectTransitionFlags() {\r
+ return _effectTransitionFlags;\r
+ }\r
+\r
+ public void setEffectTransitionFlags(short effectTransitionFlags) {\r
+ this._effectTransitionFlags = effectTransitionFlags;\r
+ }\r
+\r
+ /**\r
+ * Use one of the bitmasks MANUAL_ADVANCE_BIT ... CURSOR_VISIBLE_BIT\r
+ * @param bitmask\r
+ * @param enabled\r
+ */\r
+ public void setEffectTransitionFlagByBit(int bitmask, boolean enabled) {\r
+ if (enabled) {\r
+ _effectTransitionFlags |= bitmask;\r
+ } else {\r
+ _effectTransitionFlags &= (0xFFFF ^ bitmask);\r
+ }\r
+ }\r
+\r
+ public boolean getEffectTransitionFlagByBit(int bitmask) {\r
+ return ((_effectTransitionFlags & bitmask) != 0);\r
+ }\r
+ \r
+ public short getSpeed() {\r
+ return _speed;\r
+ }\r
+\r
+ public void setSpeed(short speed) {\r
+ this._speed = speed;\r
+ }\r
+}\r