1 2 /* ==================================================================== 3 * The Apache Software License, Version 1.1 4 * 5 * Copyright (c) 2002 The Apache Software Foundation. All rights 6 * reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in 17 * the documentation and/or other materials provided with the 18 * distribution. 19 * 20 * 3. The end-user documentation included with the redistribution, 21 * if any, must include the following acknowledgment: 22 * "This product includes software developed by the 23 * Apache Software Foundation (http://www.apache.org/)." 24 * Alternately, this acknowledgment may appear in the software itself, 25 * if and wherever such third-party acknowledgments normally appear. 26 * 27 * 4. The names "Apache" and "Apache Software Foundation" and 28 * "Apache POI" must not be used to endorse or promote products 29 * derived from this software without prior written permission. For 30 * written permission, please contact apache@apache.org. 31 * 32 * 5. Products derived from this software may not be called "Apache", 33 * "Apache POI", nor may "Apache" appear in their name, without 34 * prior written permission of the Apache Software Foundation. 35 * 36 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 37 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 38 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 39 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 42 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 43 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 44 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 45 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 46 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 47 * SUCH DAMAGE. 48 * ==================================================================== 49 * 50 * This software consists of voluntary contributions made by many 51 * individuals on behalf of the Apache Software Foundation. For more 52 * information on the Apache Software Foundation, please see 53 * <http://www.apache.org/>. 54 */ 55 56 package org.apache.poi.hssf.record; 57 58 import org.apache.poi.util.BitField; 59 import org.apache.poi.util.LittleEndian; 60 61 /** 62 * Title: WSBool Record.<p> 63 * Description: stores workbook settings (aka its a big "everything we didn't 64 * put somewhere else")<P> 65 * REFERENCE: PG 425 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P> 66 * @author Andrew C. Oliver (acoliver at apache dot org) 67 * @author Glen Stampoultzis (gstamp@iprimus.com.au) 68 * @version 2.0-pre 69 */ 70 71 public class WSBoolRecord 72 extends Record 73 { 74 public final static short sid = 0x81; 75 private byte field_1_wsbool; // crappy names are because this is really one big short field (2byte) 76 private byte field_2_wsbool; // but the docs inconsistantly use it as 2 seperate bytes 77 78 // I decided to be consistant in this way. 79 static final private BitField autobreaks = 80 new BitField(0x01); // are automatic page breaks visible 81 82 // bits 1 to 3 unused 83 static final private BitField dialog = 84 new BitField(0x10); // is sheet dialog sheet 85 static final private BitField applystyles = 86 new BitField(0x20); // whether to apply automatic styles to outlines 87 static final private BitField rowsumsbelow = new BitField( 88 0x40); // whether summary rows will appear below detail in outlines 89 static final private BitField rowsumsright = new BitField( 90 0x80); // whether summary rows will appear right of the detail in outlines 91 static final private BitField fittopage = 92 new BitField(0x01); // whether to fit stuff to the page 93 94 // bit 2 reserved 95 static final private BitField displayguts = new BitField( 96 0x06); // whether to display outline symbols (in the gutters) 97 98 // bits 4-5 reserved 99 static final private BitField alternateexpression = // whether to use alternate expression eval 100 new BitField(0x40); 101 static final private BitField alternateformula = // whether to use alternate formula entry 102 new BitField(0x80); 103 104 public WSBoolRecord() 105 { 106 } 107 108 /** 109 * Constructs a WSBool record and sets its fields appropriately. 110 * 111 * @param id id must be 0x81 or an exception will be throw upon validation 112 * @param size the size of the data area of the record 113 * @param data data of the record (should not contain sid/len) 114 */ 115 116 public WSBoolRecord(short id, short size, byte [] data) 117 { 118 super(id, size, data); 119 } 120 121 /** 122 * Constructs a WSBool record and sets its fields appropriately. 123 * 124 * @param id id must be 0x81 or an exception will be throw upon validation 125 * @param size the size of the data area of the record 126 * @param data data of the record (should not contain sid/len) 127 */ 128 129 public WSBoolRecord(short id, short size, byte [] data, int offset) 130 { 131 super(id, size, data, offset); 132 } 133 134 protected void validateSid(short id) 135 { 136 if (id != sid) 137 { 138 throw new RecordFormatException("NOT A WSBoolRECORD"); 139 } 140 } 141 142 protected void fillFields(byte [] data, short size, int offset) 143 { 144 field_1_wsbool = 145 data[ 1 + offset ]; // backwards because theoretically this is one short field 146 field_2_wsbool = 147 data[ 0 + offset ]; // but it was easier to implement it this way to avoid confusion 148 } // because the dev kit shows the masks for it as 2 byte fields 149 150 // why? Why ask why? But don't drink bud dry as its a really 151 // crappy beer, try the czech "Budvar" beer (which is the real 152 // budweiser though its ironically good...its sold in the USs 153 // as czechvar --- odd that they had the name first but can't 154 // use it)... 155 156 /** 157 * set first byte (see bit setters) 158 */ 159 160 public void setWSBool1(byte bool1) 161 { 162 field_1_wsbool = bool1; 163 } 164 165 // bool1 bitfields 166 167 /** 168 * show automatic page breaks or not 169 * @param ab whether to show auto page breaks 170 */ 171 172 public void setAutobreaks(boolean ab) 173 { 174 field_1_wsbool = autobreaks.setByteBoolean(field_1_wsbool, ab); 175 } 176 177 /** 178 * set whether sheet is a dialog sheet or not 179 * @param isDialog or not 180 */ 181 182 public void setDialog(boolean isDialog) 183 { 184 field_1_wsbool = dialog.setByteBoolean(field_1_wsbool, isDialog); 185 } 186 187 /** 188 * set if row summaries appear below detail in the outline 189 * @param below or not 190 */ 191 192 public void setRowSumsBelow(boolean below) 193 { 194 field_1_wsbool = rowsumsbelow.setByteBoolean(field_1_wsbool, below); 195 } 196 197 /** 198 * set if col summaries appear right of the detail in the outline 199 * @param right or not 200 */ 201 202 public void setRowSumsRight(boolean right) 203 { 204 field_1_wsbool = rowsumsright.setByteBoolean(field_1_wsbool, right); 205 } 206 207 // end bitfields 208 209 /** 210 * set the second byte (see bit setters) 211 */ 212 213 public void setWSBool2(byte bool2) 214 { 215 field_2_wsbool = field_2_wsbool = bool2; 216 } 217 218 // bool2 bitfields 219 220 /** 221 * fit to page option is on 222 * @param fit2page fit or not 223 */ 224 225 public void setFitToPage(boolean fit2page) 226 { 227 field_2_wsbool = fittopage.setByteBoolean(field_2_wsbool, fit2page); 228 } 229 230 /** 231 * set whether to display the guts or not 232 * 233 * @param guts or no guts (or glory) 234 */ 235 236 public void setDisplayGuts(boolean guts) 237 { 238 field_2_wsbool = displayguts.setByteBoolean(field_2_wsbool, guts); 239 } 240 241 /** 242 * whether alternate expression evaluation is on 243 * @param altexp alternative expression evaluation or not 244 */ 245 246 public void setAlternateExpression(boolean altexp) 247 { 248 field_2_wsbool = alternateexpression.setByteBoolean(field_2_wsbool, 249 altexp); 250 } 251 252 /** 253 * whether alternative formula entry is on 254 * @param formula alternative formulas or not 255 */ 256 257 public void setAlternateFormula(boolean formula) 258 { 259 field_2_wsbool = alternateformula.setByteBoolean(field_2_wsbool, 260 formula); 261 } 262 263 // end bitfields 264 265 /** 266 * get first byte (see bit getters) 267 */ 268 269 public byte getWSBool1() 270 { 271 return field_1_wsbool; 272 } 273 274 // bool1 bitfields 275 276 /** 277 * show automatic page breaks or not 278 * @return whether to show auto page breaks 279 */ 280 281 public boolean getAutobreaks() 282 { 283 return autobreaks.isSet(field_1_wsbool); 284 } 285 286 /** 287 * get whether sheet is a dialog sheet or not 288 * @return isDialog or not 289 */ 290 291 public boolean getDialog() 292 { 293 return dialog.isSet(field_1_wsbool); 294 } 295 296 /** 297 * get if row summaries appear below detail in the outline 298 * @return below or not 299 */ 300 301 public boolean getRowSumsBelow() 302 { 303 return rowsumsbelow.isSet(field_1_wsbool); 304 } 305 306 /** 307 * get if col summaries appear right of the detail in the outline 308 * @return right or not 309 */ 310 311 public boolean getRowSumsRight() 312 { 313 return rowsumsright.isSet(field_1_wsbool); 314 } 315 316 // end bitfields 317 318 /** 319 * get the second byte (see bit getters) 320 */ 321 322 public byte getWSBool2() 323 { 324 return field_2_wsbool; 325 } 326 327 // bool2 bitfields 328 329 /** 330 * fit to page option is on 331 * @return fit or not 332 */ 333 334 public boolean getFitToPage() 335 { 336 return fittopage.isSet(field_2_wsbool); 337 } 338 339 /** 340 * get whether to display the guts or not 341 * 342 * @return guts or no guts (or glory) 343 */ 344 345 public boolean getDisplayGuts() 346 { 347 return displayguts.isSet(field_2_wsbool); 348 } 349 350 /** 351 * whether alternate expression evaluation is on 352 * @return alternative expression evaluation or not 353 */ 354 355 public boolean getAlternateExpression() 356 { 357 return alternateexpression.isSet(field_2_wsbool); 358 } 359 360 /** 361 * whether alternative formula entry is on 362 * @return alternative formulas or not 363 */ 364 365 public boolean getAlternateFormula() 366 { 367 return alternateformula.isSet(field_2_wsbool); 368 } 369 370 // end bitfields 371 public String toString() 372 { 373 StringBuffer buffer = new StringBuffer(); 374 375 buffer.append("[WSBOOL]\n"); 376 buffer.append(" .wsbool1 = ") 377 .append(Integer.toHexString(getWSBool1())).append("\n"); 378 buffer.append(" .autobreaks = ").append(getAutobreaks()) 379 .append("\n"); 380 buffer.append(" .dialog = ").append(getDialog()) 381 .append("\n"); 382 buffer.append(" .rowsumsbelw= ").append(getRowSumsBelow()) 383 .append("\n"); 384 buffer.append(" .rowsumsrigt= ").append(getRowSumsRight()) 385 .append("\n"); 386 buffer.append(" .wsbool2 = ") 387 .append(Integer.toHexString(getWSBool2())).append("\n"); 388 buffer.append(" .fittopage = ").append(getFitToPage()) 389 .append("\n"); 390 buffer.append(" .displayguts= ").append(getDisplayGuts()) 391 .append("\n"); 392 buffer.append(" .alternateex= ") 393 .append(getAlternateExpression()).append("\n"); 394 buffer.append(" .alternatefo= ").append(getAlternateFormula()) 395 .append("\n"); 396 buffer.append("[/WSBOOL]\n"); 397 return buffer.toString(); 398 } 399 400 public int serialize(int offset, byte [] data) 401 { 402 LittleEndian.putShort(data, 0 + offset, sid); 403 LittleEndian.putShort(data, 2 + offset, ( short ) 0x2); 404 data[ 5 + offset ] = getWSBool1(); 405 data[ 4 + offset ] = getWSBool2(); 406 return getRecordSize(); 407 } 408 409 public int getRecordSize() 410 { 411 return 6; 412 } 413 414 public short getSid() 415 { 416 return this.sid; 417 } 418 } 419