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 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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 org.apache.poi.util.BitField;
  17. import org.apache.poi.util.BitFieldFactory;
  18. import org.apache.poi.util.LittleEndianOutput;
  19. /**
  20. * Title: Window1 Record<P>
  21. * Description: Stores the attributes of the workbook window. This is basically
  22. * so the gui knows how big to make the window holding the spreadsheet
  23. * document.<P>
  24. * REFERENCE: PG 421 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
  25. * @author Andrew C. Oliver (acoliver at apache dot org)
  26. * @version 2.0-pre
  27. */
  28. public final class WindowOneRecord extends StandardRecord {
  29. public final static short sid = 0x3d;
  30. // our variable names stolen from old TV sets.
  31. private short field_1_h_hold; // horizontal position
  32. private short field_2_v_hold; // vertical position
  33. private short field_3_width;
  34. private short field_4_height;
  35. private short field_5_options;
  36. static final private BitField hidden =
  37. BitFieldFactory.getInstance(0x01); // is this window is hidden
  38. static final private BitField iconic =
  39. BitFieldFactory.getInstance(0x02); // is this window is an icon
  40. static final private BitField reserved = BitFieldFactory.getInstance(0x04); // reserved
  41. static final private BitField hscroll =
  42. BitFieldFactory.getInstance(0x08); // display horizontal scrollbar
  43. static final private BitField vscroll =
  44. BitFieldFactory.getInstance(0x10); // display vertical scrollbar
  45. static final private BitField tabs =
  46. BitFieldFactory.getInstance(0x20); // display tabs at the bottom
  47. // all the rest are "reserved"
  48. private int field_6_active_sheet;
  49. private int field_7_first_visible_tab;
  50. private short field_8_num_selected_tabs;
  51. private short field_9_tab_width_ratio;
  52. public WindowOneRecord()
  53. {
  54. }
  55. public WindowOneRecord(RecordInputStream in)
  56. {
  57. field_1_h_hold = in.readShort();
  58. field_2_v_hold = in.readShort();
  59. field_3_width = in.readShort();
  60. field_4_height = in.readShort();
  61. field_5_options = in.readShort();
  62. field_6_active_sheet = in.readShort();
  63. field_7_first_visible_tab = in.readShort();
  64. field_8_num_selected_tabs = in.readShort();
  65. field_9_tab_width_ratio = in.readShort();
  66. }
  67. /**
  68. * set the horizontal position of the window (in 1/20ths of a point)
  69. * @param h - horizontal location
  70. */
  71. public void setHorizontalHold(short h)
  72. {
  73. field_1_h_hold = h;
  74. }
  75. /**
  76. * set the vertical position of the window (in 1/20ths of a point)
  77. * @param v - vertical location
  78. */
  79. public void setVerticalHold(short v)
  80. {
  81. field_2_v_hold = v;
  82. }
  83. /**
  84. * set the width of the window
  85. * @param w width
  86. */
  87. public void setWidth(short w)
  88. {
  89. field_3_width = w;
  90. }
  91. /**
  92. * set teh height of the window
  93. * @param h height
  94. */
  95. public void setHeight(short h)
  96. {
  97. field_4_height = h;
  98. }
  99. /**
  100. * set the options bitmask (see bit setters)
  101. *
  102. * @param o - the bitmask
  103. */
  104. public void setOptions(short o)
  105. {
  106. field_5_options = o;
  107. }
  108. // bitfields for options
  109. /**
  110. * set whether the window is hidden or not
  111. * @param ishidden or not
  112. */
  113. public void setHidden(boolean ishidden)
  114. {
  115. field_5_options = hidden.setShortBoolean(field_5_options, ishidden);
  116. }
  117. /**
  118. * set whether the window has been iconized or not
  119. * @param isiconic iconize or not
  120. */
  121. public void setIconic(boolean isiconic)
  122. {
  123. field_5_options = iconic.setShortBoolean(field_5_options, isiconic);
  124. }
  125. /**
  126. * set whether to display the horizontal scrollbar or not
  127. * @param scroll display or not
  128. */
  129. public void setDisplayHorizonalScrollbar(boolean scroll)
  130. {
  131. field_5_options = hscroll.setShortBoolean(field_5_options, scroll);
  132. }
  133. /**
  134. * set whether to display the vertical scrollbar or not
  135. * @param scroll display or not
  136. */
  137. public void setDisplayVerticalScrollbar(boolean scroll)
  138. {
  139. field_5_options = vscroll.setShortBoolean(field_5_options, scroll);
  140. }
  141. /**
  142. * set whether to display the tabs or not
  143. * @param disptabs display or not
  144. */
  145. public void setDisplayTabs(boolean disptabs)
  146. {
  147. field_5_options = tabs.setShortBoolean(field_5_options, disptabs);
  148. }
  149. // end bitfields
  150. public void setActiveSheetIndex(int index) {
  151. field_6_active_sheet = index;
  152. }
  153. /**
  154. * deprecated May 2008
  155. * @deprecated - Misleading name - use setActiveSheetIndex()
  156. */
  157. public void setSelectedTab(short s)
  158. {
  159. setActiveSheetIndex(s);
  160. }
  161. /**
  162. * Sets the first visible sheet in the worksheet tab-bar. This method does <b>not</b>
  163. * hide, select or focus sheets. It just sets the scroll position in the tab-bar.
  164. * @param t the sheet index of the tab that will become the first in the tab-bar
  165. */
  166. public void setFirstVisibleTab(int t) {
  167. field_7_first_visible_tab = t;
  168. }
  169. /**
  170. * deprecated May 2008
  171. * @deprecated - Misleading name - use setFirstVisibleTab()
  172. */
  173. public void setDisplayedTab(short t) {
  174. setFirstVisibleTab(t);
  175. }
  176. /**
  177. * set the number of selected tabs
  178. * @param n number of tabs
  179. */
  180. public void setNumSelectedTabs(short n)
  181. {
  182. field_8_num_selected_tabs = n;
  183. }
  184. /**
  185. * ratio of the width of the tabs to the horizontal scrollbar
  186. * @param r ratio
  187. */
  188. public void setTabWidthRatio(short r)
  189. {
  190. field_9_tab_width_ratio = r;
  191. }
  192. /**
  193. * get the horizontal position of the window (in 1/20ths of a point)
  194. * @return h - horizontal location
  195. */
  196. public short getHorizontalHold()
  197. {
  198. return field_1_h_hold;
  199. }
  200. /**
  201. * get the vertical position of the window (in 1/20ths of a point)
  202. * @return v - vertical location
  203. */
  204. public short getVerticalHold()
  205. {
  206. return field_2_v_hold;
  207. }
  208. /**
  209. * get the width of the window
  210. * @return width
  211. */
  212. public short getWidth()
  213. {
  214. return field_3_width;
  215. }
  216. /**
  217. * get the height of the window
  218. * @return height
  219. */
  220. public short getHeight()
  221. {
  222. return field_4_height;
  223. }
  224. /**
  225. * get the options bitmask (see bit setters)
  226. *
  227. * @return o - the bitmask
  228. */
  229. public short getOptions()
  230. {
  231. return field_5_options;
  232. }
  233. // bitfields for options
  234. /**
  235. * get whether the window is hidden or not
  236. * @return ishidden or not
  237. */
  238. public boolean getHidden()
  239. {
  240. return hidden.isSet(field_5_options);
  241. }
  242. /**
  243. * get whether the window has been iconized or not
  244. * @return iconize or not
  245. */
  246. public boolean getIconic()
  247. {
  248. return iconic.isSet(field_5_options);
  249. }
  250. /**
  251. * get whether to display the horizontal scrollbar or not
  252. * @return display or not
  253. */
  254. public boolean getDisplayHorizontalScrollbar()
  255. {
  256. return hscroll.isSet(field_5_options);
  257. }
  258. /**
  259. * get whether to display the vertical scrollbar or not
  260. * @return display or not
  261. */
  262. public boolean getDisplayVerticalScrollbar()
  263. {
  264. return vscroll.isSet(field_5_options);
  265. }
  266. /**
  267. * get whether to display the tabs or not
  268. * @return display or not
  269. */
  270. public boolean getDisplayTabs()
  271. {
  272. return tabs.isSet(field_5_options);
  273. }
  274. // end options bitfields
  275. /**
  276. * @return the index of the currently displayed sheet
  277. */
  278. public int getActiveSheetIndex() {
  279. return field_6_active_sheet;
  280. }
  281. /**
  282. * deprecated May 2008
  283. * @deprecated - Misleading name - use getActiveSheetIndex()
  284. */
  285. public short getSelectedTab()
  286. {
  287. return (short) getActiveSheetIndex();
  288. }
  289. /**
  290. * @return the first visible sheet in the worksheet tab-bar.
  291. * I.E. the scroll position of the tab-bar.
  292. */
  293. public int getFirstVisibleTab() {
  294. return field_7_first_visible_tab;
  295. }
  296. /**
  297. * deprecated May 2008
  298. * @deprecated - Misleading name - use getFirstVisibleTab()
  299. */
  300. public short getDisplayedTab()
  301. {
  302. return (short) getFirstVisibleTab();
  303. }
  304. /**
  305. * get the number of selected tabs
  306. * @return number of tabs
  307. */
  308. public short getNumSelectedTabs()
  309. {
  310. return field_8_num_selected_tabs;
  311. }
  312. /**
  313. * ratio of the width of the tabs to the horizontal scrollbar
  314. * @return ratio
  315. */
  316. public short getTabWidthRatio()
  317. {
  318. return field_9_tab_width_ratio;
  319. }
  320. public String toString()
  321. {
  322. StringBuffer buffer = new StringBuffer();
  323. buffer.append("[WINDOW1]\n");
  324. buffer.append(" .h_hold = ")
  325. .append(Integer.toHexString(getHorizontalHold())).append("\n");
  326. buffer.append(" .v_hold = ")
  327. .append(Integer.toHexString(getVerticalHold())).append("\n");
  328. buffer.append(" .width = ")
  329. .append(Integer.toHexString(getWidth())).append("\n");
  330. buffer.append(" .height = ")
  331. .append(Integer.toHexString(getHeight())).append("\n");
  332. buffer.append(" .options = ")
  333. .append(Integer.toHexString(getOptions())).append("\n");
  334. buffer.append(" .hidden = ").append(getHidden())
  335. .append("\n");
  336. buffer.append(" .iconic = ").append(getIconic())
  337. .append("\n");
  338. buffer.append(" .hscroll = ")
  339. .append(getDisplayHorizontalScrollbar()).append("\n");
  340. buffer.append(" .vscroll = ")
  341. .append(getDisplayVerticalScrollbar()).append("\n");
  342. buffer.append(" .tabs = ").append(getDisplayTabs())
  343. .append("\n");
  344. buffer.append(" .activeSheet = ")
  345. .append(Integer.toHexString(getActiveSheetIndex())).append("\n");
  346. buffer.append(" .firstVisibleTab = ")
  347. .append(Integer.toHexString(getFirstVisibleTab())).append("\n");
  348. buffer.append(" .numselectedtabs = ")
  349. .append(Integer.toHexString(getNumSelectedTabs())).append("\n");
  350. buffer.append(" .tabwidthratio = ")
  351. .append(Integer.toHexString(getTabWidthRatio())).append("\n");
  352. buffer.append("[/WINDOW1]\n");
  353. return buffer.toString();
  354. }
  355. public void serialize(LittleEndianOutput out) {
  356. out.writeShort(getHorizontalHold());
  357. out.writeShort(getVerticalHold());
  358. out.writeShort(getWidth());
  359. out.writeShort(getHeight());
  360. out.writeShort(getOptions());
  361. out.writeShort(getActiveSheetIndex());
  362. out.writeShort(getFirstVisibleTab());
  363. out.writeShort(getNumSelectedTabs());
  364. out.writeShort(getTabWidthRatio());
  365. }
  366. protected int getDataSize() {
  367. return 18;
  368. }
  369. public short getSid()
  370. {
  371. return sid;
  372. }
  373. }