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.

FFDataBaseAbstractType.java 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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.hwpf.model.types;
  16. import java.util.Objects;
  17. import org.apache.poi.util.BitField;
  18. import org.apache.poi.util.Internal;
  19. import org.apache.poi.util.LittleEndian;
  20. /**
  21. * The FFData structure specifies form field data for a text box, check box, or drop-down list box.
  22. */
  23. @Internal
  24. public abstract class FFDataBaseAbstractType
  25. {
  26. protected long field_1_version;
  27. protected short field_2_bits;
  28. /**/private static final BitField iType = new BitField(0x0003);
  29. /** Specifies that the form field is a textbox. */
  30. /* */public static final byte ITYPE_TEXT = 0;
  31. /** Specifies that the form field is a checkbox. */
  32. /* */public static final byte ITYPE_CHCK = 1;
  33. /** Specifies that the form field is a dropdown list box. */
  34. /* */public static final byte ITYPE_DROP = 2;
  35. /**/private static final BitField iRes = new BitField(0x007C);
  36. /**/private static final BitField fOwnHelp = new BitField(0x0080);
  37. /**/private static final BitField fOwnStat = new BitField(0x0100);
  38. /**/private static final BitField fProt = new BitField(0x0200);
  39. /**/private static final BitField iSize = new BitField(0x0400);
  40. /**/private static final BitField iTypeTxt = new BitField(0x3800);
  41. /** Specifies that the textbox value is regular text. */
  42. /* */public static final byte ITYPETXT_REG = 0;
  43. /** Specifies that the textbox value is a number. */
  44. /* */public static final byte ITYPETXT_NUM = 0;
  45. /** Specifies that the textbox value is a date or time. */
  46. /* */public static final byte ITYPETXT_DATE = 0;
  47. /** Specifies that the textbox value is the current date. */
  48. /* */public static final byte ITYPETXT_CURDATE = 0;
  49. /** Specifies that the textbox value is the current time. */
  50. /* */public static final byte ITYPETXT_CURTIME = 0;
  51. /** Specifies that the textbox value is calculated from an expression. The expression is given by FFData.xstzTextDef. */
  52. /* */protected static final byte ITYPETXT_CALC = 0;
  53. /**/private static final BitField fRecalc = new BitField(0x4000);
  54. /**/private static final BitField fHasListBox = new BitField(0x8000);
  55. protected int field_3_cch;
  56. protected int field_4_hps;
  57. protected FFDataBaseAbstractType()
  58. {
  59. }
  60. protected void fillFields( byte[] data, int offset )
  61. {
  62. field_1_version = LittleEndian.getUInt( data, 0x0 + offset );
  63. field_2_bits = LittleEndian.getShort( data, 0x4 + offset );
  64. field_3_cch = LittleEndian.getShort( data, 0x6 + offset );
  65. field_4_hps = LittleEndian.getShort( data, 0x8 + offset );
  66. }
  67. public void serialize( byte[] data, int offset )
  68. {
  69. LittleEndian.putUInt( data, 0x0 + offset, field_1_version );
  70. LittleEndian.putShort( data, 0x4 + offset, field_2_bits );
  71. LittleEndian.putUShort( data, 0x6 + offset, field_3_cch );
  72. LittleEndian.putUShort( data, 0x8 + offset, field_4_hps );
  73. }
  74. public byte[] serialize()
  75. {
  76. final byte[] result = new byte[ getSize() ];
  77. serialize( result, 0 );
  78. return result;
  79. }
  80. /**
  81. * Size of record
  82. */
  83. public static int getSize()
  84. {
  85. return 0 + 4 + 2 + 2 + 2;
  86. }
  87. @Override
  88. public boolean equals( Object obj )
  89. {
  90. if ( this == obj )
  91. return true;
  92. if ( obj == null )
  93. return false;
  94. if ( getClass() != obj.getClass() )
  95. return false;
  96. FFDataBaseAbstractType other = (FFDataBaseAbstractType) obj;
  97. if ( field_1_version != other.field_1_version )
  98. return false;
  99. if ( field_2_bits != other.field_2_bits )
  100. return false;
  101. if ( field_3_cch != other.field_3_cch )
  102. return false;
  103. if ( field_4_hps != other.field_4_hps )
  104. return false;
  105. return true;
  106. }
  107. @Override
  108. public int hashCode() {
  109. return Objects.hash(field_1_version, field_2_bits, field_3_cch, field_4_hps);
  110. }
  111. public String toString()
  112. {
  113. StringBuilder builder = new StringBuilder();
  114. builder.append("[FFDataBase]\n");
  115. builder.append( " .version = " );
  116. builder.append(" ( ").append( field_1_version ).append( " )\n" );
  117. builder.append( " .bits = " );
  118. builder.append(" ( ").append( field_2_bits ).append( " )\n" );
  119. builder.append(" .iType = ").append(getIType()).append('\n');
  120. builder.append(" .iRes = ").append(getIRes()).append('\n');
  121. builder.append(" .fOwnHelp = ").append(isFOwnHelp()).append('\n');
  122. builder.append(" .fOwnStat = ").append(isFOwnStat()).append('\n');
  123. builder.append(" .fProt = ").append(isFProt()).append('\n');
  124. builder.append(" .iSize = ").append(isISize()).append('\n');
  125. builder.append(" .iTypeTxt = ").append(getITypeTxt()).append('\n');
  126. builder.append(" .fRecalc = ").append(isFRecalc()).append('\n');
  127. builder.append(" .fHasListBox = ").append(isFHasListBox()).append('\n');
  128. builder.append( " .cch = " );
  129. builder.append(" ( ").append( field_3_cch ).append( " )\n" );
  130. builder.append( " .hps = " );
  131. builder.append(" ( ").append( field_4_hps ).append( " )\n" );
  132. builder.append("[/FFDataBase]");
  133. return builder.toString();
  134. }
  135. /**
  136. * An unsigned integer that MUST be 0xFFFFFFFF.
  137. */
  138. @Internal
  139. public long getVersion()
  140. {
  141. return field_1_version;
  142. }
  143. /**
  144. * An unsigned integer that MUST be 0xFFFFFFFF.
  145. */
  146. @Internal
  147. public void setVersion( long field_1_version )
  148. {
  149. this.field_1_version = field_1_version;
  150. }
  151. /**
  152. * An FFDataBits that specifies the type and state of this form field.
  153. */
  154. @Internal
  155. public short getBits()
  156. {
  157. return field_2_bits;
  158. }
  159. /**
  160. * An FFDataBits that specifies the type and state of this form field.
  161. */
  162. @Internal
  163. public void setBits( short field_2_bits )
  164. {
  165. this.field_2_bits = field_2_bits;
  166. }
  167. /**
  168. * An unsigned integer that specifies the maximum length, in characters, of the value of the textbox. This value MUST NOT exceed 32767. A value of 0 means there is no maximum length of the value of the textbox. If bits.iType is not iTypeText (0), this value MUST be 0..
  169. */
  170. @Internal
  171. public int getCch()
  172. {
  173. return field_3_cch;
  174. }
  175. /**
  176. * An unsigned integer that specifies the maximum length, in characters, of the value of the textbox. This value MUST NOT exceed 32767. A value of 0 means there is no maximum length of the value of the textbox. If bits.iType is not iTypeText (0), this value MUST be 0..
  177. */
  178. @Internal
  179. public void setCch( int field_3_cch )
  180. {
  181. this.field_3_cch = field_3_cch;
  182. }
  183. /**
  184. * An unsigned integer. If bits.iType is iTypeChck (1), hps specifies the size, in half-points, of the checkbox and MUST be between 2 and 3168, inclusive. If bits.iType is not iTypeChck (1), hps is undefined and MUST be ignored..
  185. */
  186. @Internal
  187. public int getHps()
  188. {
  189. return field_4_hps;
  190. }
  191. /**
  192. * An unsigned integer. If bits.iType is iTypeChck (1), hps specifies the size, in half-points, of the checkbox and MUST be between 2 and 3168, inclusive. If bits.iType is not iTypeChck (1), hps is undefined and MUST be ignored..
  193. */
  194. @Internal
  195. public void setHps( int field_4_hps )
  196. {
  197. this.field_4_hps = field_4_hps;
  198. }
  199. /**
  200. * Sets the iType field value.
  201. * An unsigned integer that specifies the type of the form field.
  202. */
  203. @Internal
  204. public void setIType( byte value )
  205. {
  206. field_2_bits = (short)iType.setValue(field_2_bits, value);
  207. }
  208. /**
  209. * An unsigned integer that specifies the type of the form field.
  210. * @return the iType field value.
  211. */
  212. @Internal
  213. public byte getIType()
  214. {
  215. return ( byte )iType.getValue(field_2_bits);
  216. }
  217. /**
  218. * Sets the iRes field value.
  219. * An unsigned integer. If iType is iTypeText (0), then iRes MUST be 0. If iType is iTypeChck (1), iRes specifies the state of the checkbox and MUST be 0 (unchecked), 1 (checked), or 25 (undefined). Undefined checkboxes are treated as unchecked. If iType is iTypeDrop (2), iRes specifies the current selected list box item. A value of 25 specifies the selection is undefined. Otherwise, iRes is a zero-based index into FFData.hsttbDropList.
  220. */
  221. @Internal
  222. public void setIRes( byte value )
  223. {
  224. field_2_bits = (short)iRes.setValue(field_2_bits, value);
  225. }
  226. /**
  227. * An unsigned integer. If iType is iTypeText (0), then iRes MUST be 0. If iType is iTypeChck (1), iRes specifies the state of the checkbox and MUST be 0 (unchecked), 1 (checked), or 25 (undefined). Undefined checkboxes are treated as unchecked. If iType is iTypeDrop (2), iRes specifies the current selected list box item. A value of 25 specifies the selection is undefined. Otherwise, iRes is a zero-based index into FFData.hsttbDropList.
  228. * @return the iRes field value.
  229. */
  230. @Internal
  231. public byte getIRes()
  232. {
  233. return ( byte )iRes.getValue(field_2_bits);
  234. }
  235. /**
  236. * Sets the fOwnHelp field value.
  237. * A bit that specifies whether the form field has custom help text in FFData.xstzHelpText. If fOwnHelp is 0, FFData.xstzHelpText contains an empty or auto-generated string.
  238. */
  239. @Internal
  240. public void setFOwnHelp( boolean value )
  241. {
  242. field_2_bits = (short)fOwnHelp.setBoolean(field_2_bits, value);
  243. }
  244. /**
  245. * A bit that specifies whether the form field has custom help text in FFData.xstzHelpText. If fOwnHelp is 0, FFData.xstzHelpText contains an empty or auto-generated string.
  246. * @return the fOwnHelp field value.
  247. */
  248. @Internal
  249. public boolean isFOwnHelp()
  250. {
  251. return fOwnHelp.isSet(field_2_bits);
  252. }
  253. /**
  254. * Sets the fOwnStat field value.
  255. * A bit that specifies whether the form field has custom status bar text in FFData.xstzStatText. If fOwnStat is 0, FFData.xstzStatText contains an empty or auto-generated string.
  256. */
  257. @Internal
  258. public void setFOwnStat( boolean value )
  259. {
  260. field_2_bits = (short)fOwnStat.setBoolean(field_2_bits, value);
  261. }
  262. /**
  263. * A bit that specifies whether the form field has custom status bar text in FFData.xstzStatText. If fOwnStat is 0, FFData.xstzStatText contains an empty or auto-generated string.
  264. * @return the fOwnStat field value.
  265. */
  266. @Internal
  267. public boolean isFOwnStat()
  268. {
  269. return fOwnStat.isSet(field_2_bits);
  270. }
  271. /**
  272. * Sets the fProt field value.
  273. * A bit that specifies whether the form field is protected and its value cannot be changed.
  274. */
  275. @Internal
  276. public void setFProt( boolean value )
  277. {
  278. field_2_bits = (short)fProt.setBoolean(field_2_bits, value);
  279. }
  280. /**
  281. * A bit that specifies whether the form field is protected and its value cannot be changed.
  282. * @return the fProt field value.
  283. */
  284. @Internal
  285. public boolean isFProt()
  286. {
  287. return fProt.isSet(field_2_bits);
  288. }
  289. /**
  290. * Sets the iSize field value.
  291. * A bit that specifies whether the size of a checkbox is automatically determined by the text size where the checkbox is located. This value MUST be 0 if iType is not iTypeChck (1).
  292. */
  293. @Internal
  294. public void setISize( boolean value )
  295. {
  296. field_2_bits = (short)iSize.setBoolean(field_2_bits, value);
  297. }
  298. /**
  299. * A bit that specifies whether the size of a checkbox is automatically determined by the text size where the checkbox is located. This value MUST be 0 if iType is not iTypeChck (1).
  300. * @return the iSize field value.
  301. */
  302. @Internal
  303. public boolean isISize()
  304. {
  305. return iSize.isSet(field_2_bits);
  306. }
  307. /**
  308. * Sets the iTypeTxt field value.
  309. * An unsigned integer that specifies the type of the textbox. If iType is not iTypeText (0), iTypeTxt MUST be 0 and MUST be ignored.
  310. */
  311. @Internal
  312. public void setITypeTxt( byte value )
  313. {
  314. field_2_bits = (short)iTypeTxt.setValue(field_2_bits, value);
  315. }
  316. /**
  317. * An unsigned integer that specifies the type of the textbox. If iType is not iTypeText (0), iTypeTxt MUST be 0 and MUST be ignored.
  318. * @return the iTypeTxt field value.
  319. */
  320. @Internal
  321. public byte getITypeTxt()
  322. {
  323. return ( byte )iTypeTxt.getValue(field_2_bits);
  324. }
  325. /**
  326. * Sets the fRecalc field value.
  327. * A bit that specifies whether the value of the field is automatically calculated after the field is modified.
  328. */
  329. @Internal
  330. public void setFRecalc( boolean value )
  331. {
  332. field_2_bits = (short)fRecalc.setBoolean(field_2_bits, value);
  333. }
  334. /**
  335. * A bit that specifies whether the value of the field is automatically calculated after the field is modified.
  336. * @return the fRecalc field value.
  337. */
  338. @Internal
  339. public boolean isFRecalc()
  340. {
  341. return fRecalc.isSet(field_2_bits);
  342. }
  343. /**
  344. * Sets the fHasListBox field value.
  345. * A bit that specifies that the form field has a list box. This value MUST be 1 if iType is iTypeDrop (2). Otherwise, this value MUST be 0.
  346. */
  347. @Internal
  348. public void setFHasListBox( boolean value )
  349. {
  350. field_2_bits = (short)fHasListBox.setBoolean(field_2_bits, value);
  351. }
  352. /**
  353. * A bit that specifies that the form field has a list box. This value MUST be 1 if iType is iTypeDrop (2). Otherwise, this value MUST be 0.
  354. * @return the fHasListBox field value.
  355. */
  356. @Internal
  357. public boolean isFHasListBox()
  358. {
  359. return fHasListBox.isSet(field_2_bits);
  360. }
  361. } // END OF CLASS