You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WindowOneRecord.java 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hssf.record;
  16. import static org.apache.poi.util.GenericRecordUtil.getBitsAsString;
  17. import java.util.Map;
  18. import java.util.function.Supplier;
  19. import org.apache.poi.util.BitField;
  20. import org.apache.poi.util.BitFieldFactory;
  21. import org.apache.poi.util.GenericRecordUtil;
  22. import org.apache.poi.util.LittleEndianOutput;
  23. /**
  24. * Stores the attributes of the workbook window.
  25. * This is basically so the gui knows how big to make the window holding the spreadsheet document.
  26. *
  27. * @version 2.0-pre
  28. */
  29. public final class WindowOneRecord extends StandardRecord {
  30. public static final short sid = 0x3d;
  31. // horizontal position
  32. private short field_1_h_hold;
  33. // vertical position
  34. private short field_2_v_hold;
  35. private short field_3_width;
  36. private short field_4_height;
  37. private short field_5_options;
  38. // is this window is hidden
  39. static final private BitField hidden = BitFieldFactory.getInstance(0x01);
  40. // is this window is an icon
  41. static final private BitField iconic = BitFieldFactory.getInstance(0x02);
  42. // reserved
  43. @SuppressWarnings("unused")
  44. static final private BitField reserved = BitFieldFactory.getInstance(0x04);
  45. // display horizontal scrollbar
  46. static final private BitField hscroll = BitFieldFactory.getInstance(0x08);
  47. // display vertical scrollbar
  48. static final private BitField vscroll = BitFieldFactory.getInstance(0x10);
  49. // display tabs at the bottom
  50. static final private BitField tabs = BitFieldFactory.getInstance(0x20);
  51. // all the rest are "reserved"
  52. private int field_6_active_sheet;
  53. private int field_7_first_visible_tab;
  54. private short field_8_num_selected_tabs;
  55. private short field_9_tab_width_ratio;
  56. public WindowOneRecord() {}
  57. public WindowOneRecord(WindowOneRecord other) {
  58. super(other);
  59. field_1_h_hold = other.field_1_h_hold;
  60. field_2_v_hold = other.field_2_v_hold;
  61. field_3_width = other.field_3_width;
  62. field_4_height = other.field_4_height;
  63. field_5_options = other.field_5_options;
  64. field_6_active_sheet = other.field_6_active_sheet;
  65. field_7_first_visible_tab = other.field_7_first_visible_tab;
  66. field_8_num_selected_tabs = other.field_8_num_selected_tabs;
  67. field_9_tab_width_ratio = other.field_9_tab_width_ratio;
  68. }
  69. public WindowOneRecord(RecordInputStream in) {
  70. field_1_h_hold = in.readShort();
  71. field_2_v_hold = in.readShort();
  72. field_3_width = in.readShort();
  73. field_4_height = in.readShort();
  74. field_5_options = in.readShort();
  75. field_6_active_sheet = in.readShort();
  76. field_7_first_visible_tab = in.readShort();
  77. field_8_num_selected_tabs = in.readShort();
  78. field_9_tab_width_ratio = in.readShort();
  79. }
  80. /**
  81. * set the horizontal position of the window (in 1/20ths of a point)
  82. * @param h - horizontal location
  83. */
  84. public void setHorizontalHold(short h)
  85. {
  86. field_1_h_hold = h;
  87. }
  88. /**
  89. * set the vertical position of the window (in 1/20ths of a point)
  90. * @param v - vertical location
  91. */
  92. public void setVerticalHold(short v)
  93. {
  94. field_2_v_hold = v;
  95. }
  96. /**
  97. * set the width of the window
  98. * @param w width
  99. */
  100. public void setWidth(short w)
  101. {
  102. field_3_width = w;
  103. }
  104. /**
  105. * set teh height of the window
  106. * @param h height
  107. */
  108. public void setHeight(short h)
  109. {
  110. field_4_height = h;
  111. }
  112. /**
  113. * set the options bitmask (see bit setters)
  114. *
  115. * @param o - the bitmask
  116. */
  117. public void setOptions(short o)
  118. {
  119. field_5_options = o;
  120. }
  121. // bitfields for options
  122. /**
  123. * set whether the window is hidden or not
  124. * @param ishidden or not
  125. */
  126. public void setHidden(boolean ishidden)
  127. {
  128. field_5_options = hidden.setShortBoolean(field_5_options, ishidden);
  129. }
  130. /**
  131. * set whether the window has been iconized or not
  132. * @param isiconic iconize or not
  133. */
  134. public void setIconic(boolean isiconic)
  135. {
  136. field_5_options = iconic.setShortBoolean(field_5_options, isiconic);
  137. }
  138. /**
  139. * set whether to display the horizontal scrollbar or not
  140. * @param scroll display or not
  141. */
  142. public void setDisplayHorizonalScrollbar(boolean scroll)
  143. {
  144. field_5_options = hscroll.setShortBoolean(field_5_options, scroll);
  145. }
  146. /**
  147. * set whether to display the vertical scrollbar or not
  148. * @param scroll display or not
  149. */
  150. public void setDisplayVerticalScrollbar(boolean scroll)
  151. {
  152. field_5_options = vscroll.setShortBoolean(field_5_options, scroll);
  153. }
  154. /**
  155. * set whether to display the tabs or not
  156. * @param disptabs display or not
  157. */
  158. public void setDisplayTabs(boolean disptabs)
  159. {
  160. field_5_options = tabs.setShortBoolean(field_5_options, disptabs);
  161. }
  162. // end bitfields
  163. public void setActiveSheetIndex(int index) {
  164. field_6_active_sheet = index;
  165. }
  166. /**
  167. * Sets the first visible sheet in the worksheet tab-bar. This method does <b>not</b>
  168. * hide, select or focus sheets. It just sets the scroll position in the tab-bar.
  169. * @param t the sheet index of the tab that will become the first in the tab-bar
  170. */
  171. public void setFirstVisibleTab(int t) {
  172. field_7_first_visible_tab = t;
  173. }
  174. /**
  175. * set the number of selected tabs
  176. * @param n number of tabs
  177. */
  178. public void setNumSelectedTabs(short n)
  179. {
  180. field_8_num_selected_tabs = n;
  181. }
  182. /**
  183. * ratio of the width of the tabs to the horizontal scrollbar
  184. * @param r ratio
  185. */
  186. public void setTabWidthRatio(short r)
  187. {
  188. field_9_tab_width_ratio = r;
  189. }
  190. /**
  191. * get the horizontal position of the window (in 1/20ths of a point)
  192. * @return h - horizontal location
  193. */
  194. public short getHorizontalHold()
  195. {
  196. return field_1_h_hold;
  197. }
  198. /**
  199. * get the vertical position of the window (in 1/20ths of a point)
  200. * @return v - vertical location
  201. */
  202. public short getVerticalHold()
  203. {
  204. return field_2_v_hold;
  205. }
  206. /**
  207. * get the width of the window
  208. * @return width
  209. */
  210. public short getWidth()
  211. {
  212. return field_3_width;
  213. }
  214. /**
  215. * get the height of the window
  216. * @return height
  217. */
  218. public short getHeight()
  219. {
  220. return field_4_height;
  221. }
  222. /**
  223. * get the options bitmask (see bit setters)
  224. *
  225. * @return o - the bitmask
  226. */
  227. public short getOptions()
  228. {
  229. return field_5_options;
  230. }
  231. // bitfields for options
  232. /**
  233. * get whether the window is hidden or not
  234. * @return ishidden or not
  235. */
  236. public boolean getHidden()
  237. {
  238. return hidden.isSet(field_5_options);
  239. }
  240. /**
  241. * get whether the window has been iconized or not
  242. * @return iconize or not
  243. */
  244. public boolean getIconic()
  245. {
  246. return iconic.isSet(field_5_options);
  247. }
  248. /**
  249. * get whether to display the horizontal scrollbar or not
  250. * @return display or not
  251. */
  252. public boolean getDisplayHorizontalScrollbar()
  253. {
  254. return hscroll.isSet(field_5_options);
  255. }
  256. /**
  257. * get whether to display the vertical scrollbar or not
  258. * @return display or not
  259. */
  260. public boolean getDisplayVerticalScrollbar()
  261. {
  262. return vscroll.isSet(field_5_options);
  263. }
  264. /**
  265. * get whether to display the tabs or not
  266. * @return display or not
  267. */
  268. public boolean getDisplayTabs()
  269. {
  270. return tabs.isSet(field_5_options);
  271. }
  272. // end options bitfields
  273. /**
  274. * @return the index of the currently displayed sheet
  275. */
  276. public int getActiveSheetIndex() {
  277. return field_6_active_sheet;
  278. }
  279. /**
  280. * @return the first visible sheet in the worksheet tab-bar.
  281. * I.E. the scroll position of the tab-bar.
  282. */
  283. public int getFirstVisibleTab() {
  284. return field_7_first_visible_tab;
  285. }
  286. /**
  287. * get the number of selected tabs
  288. * @return number of tabs
  289. */
  290. public short getNumSelectedTabs()
  291. {
  292. return field_8_num_selected_tabs;
  293. }
  294. /**
  295. * ratio of the width of the tabs to the horizontal scrollbar
  296. * @return ratio
  297. */
  298. public short getTabWidthRatio()
  299. {
  300. return field_9_tab_width_ratio;
  301. }
  302. public void serialize(LittleEndianOutput out) {
  303. out.writeShort(getHorizontalHold());
  304. out.writeShort(getVerticalHold());
  305. out.writeShort(getWidth());
  306. out.writeShort(getHeight());
  307. out.writeShort(getOptions());
  308. out.writeShort(getActiveSheetIndex());
  309. out.writeShort(getFirstVisibleTab());
  310. out.writeShort(getNumSelectedTabs());
  311. out.writeShort(getTabWidthRatio());
  312. }
  313. protected int getDataSize() {
  314. return 18;
  315. }
  316. public short getSid()
  317. {
  318. return sid;
  319. }
  320. @Override
  321. public WindowOneRecord copy() {
  322. return new WindowOneRecord(this);
  323. }
  324. @Override
  325. public HSSFRecordTypes getGenericRecordType() {
  326. return HSSFRecordTypes.WINDOW_ONE;
  327. }
  328. @Override
  329. public Map<String, Supplier<?>> getGenericProperties() {
  330. return GenericRecordUtil.getGenericProperties(
  331. "horizontalHold", this::getHorizontalHold,
  332. "verticalHold", this::getVerticalHold,
  333. "width", this::getWidth,
  334. "options", getBitsAsString(this::getOptions,
  335. new BitField[]{hidden, iconic, reserved, hscroll, vscroll, tabs},
  336. new String[]{"HIDDEN", "ICONIC", "RESERVED", "HSCROLL", "VSCROLL", "TABS"}),
  337. "activeSheetIndex", this::getActiveSheetIndex,
  338. "firstVisibleTab", this::getFirstVisibleTab,
  339. "numSelectedTabs", this::getNumSelectedTabs,
  340. "tabWidthRatio", this::getTabWidthRatio
  341. );
  342. }
  343. }