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 * @author Jason Height (jheight at chariot dot net dot au) 69 * @version 2.0-pre 70 */ 71 72 public class WSBoolRecord 73 extends Record 74 { 75 public final static short sid = 0x81; 76 private byte field_1_wsbool; // crappy names are because this is really one big short field (2byte) 77 private byte field_2_wsbool; // but the docs inconsistantly use it as 2 seperate bytes 78 79 // I decided to be consistant in this way. 80 static final private BitField autobreaks = 81 new BitField(0x01); // are automatic page breaks visible 82 83 // bits 1 to 3 unused 84 static final private BitField dialog = 85 new BitField(0x10); // is sheet dialog sheet 86 static final private BitField applystyles = 87 new BitField(0x20); // whether to apply automatic styles to outlines 88 static final private BitField rowsumsbelow = new BitField( 89 0x40); // whether summary rows will appear below detail in outlines 90 static final private BitField rowsumsright = new BitField( 91 0x80); // whether summary rows will appear right of the detail in outlines 92 static final private BitField fittopage = 93 new BitField(0x01); // whether to fit stuff to the page 94 95 // bit 2 reserved 96 static final private BitField displayguts = new BitField( 97 0x06); // whether to display outline symbols (in the gutters) 98 99 // bits 4-5 reserved 100 static final private BitField alternateexpression = // whether to use alternate expression eval 101 new BitField(0x40); 102 static final private BitField alternateformula = // whether to use alternate formula entry 103 new BitField(0x80); 104 105 public WSBoolRecord() 106 { 107 } 108 109 /** 110 * Constructs a WSBool record and sets its fields appropriately. 111 * 112 * @param id id must be 0x81 or an exception will be throw upon validation 113 * @param size the size of the data area of the record 114 * @param data data of the record (should not contain sid/len) 115 */ 116 117 public WSBoolRecord(short id, short size, byte [] data) 118 { 119 super(id, size, data); 120 } 121 122 /** 123 * Constructs a WSBool record and sets its fields appropriately. 124 * 125 * @param id id must be 0x81 or an exception will be throw upon validation 126 * @param size the size of the data area of the record 127 * @param data data of the record (should not contain sid/len) 128 */ 129 130 public WSBoolRecord(short id, short size, byte [] data, int offset) 131 { 132 super(id, size, data, offset); 133 } 134 135 protected void validateSid(short id) 136 { 137 if (id != sid) 138 { 139 throw new RecordFormatException("NOT A WSBoolRECORD"); 140 } 141 } 142 143 protected void fillFields(byte [] data, short size, int offset) 144 { 145 field_1_wsbool = 146 data[ 1 + offset ]; // backwards because theoretically this is one short field 147 field_2_wsbool = 148 data[ 0 + offset ]; // but it was easier to implement it this way to avoid confusion 149 } // because the dev kit shows the masks for it as 2 byte fields 150 151 // why? Why ask why? But don't drink bud dry as its a really 152 // crappy beer, try the czech "Budvar" beer (which is the real 153 // budweiser though its ironically good...its sold in the USs 154 // as czechvar --- odd that they had the name first but can't 155 // use it)... 156 157 /** 158 * set first byte (see bit setters) 159 */ 160 161 public void setWSBool1(byte bool1) 162 { 163 field_1_wsbool = bool1; 164 } 165 166 // bool1 bitfields 167 168 /** 169 * show automatic page breaks or not 170 * @param ab whether to show auto page breaks 171 */ 172 173 public void setAutobreaks(boolean ab) 174 { 175 field_1_wsbool = autobreaks.setByteBoolean(field_1_wsbool, ab); 176 } 177 178 /** 179 * set whether sheet is a dialog sheet or not 180 * @param isDialog or not 181 */ 182 183 public void setDialog(boolean isDialog) 184 { 185 field_1_wsbool = dialog.setByteBoolean(field_1_wsbool, isDialog); 186 } 187 188 /** 189 * set if row summaries appear below detail in the outline 190 * @param below or not 191 */ 192 193 public void setRowSumsBelow(boolean below) 194 { 195 field_1_wsbool = rowsumsbelow.setByteBoolean(field_1_wsbool, below); 196 } 197 198 /** 199 * set if col summaries appear right of the detail in the outline 200 * @param right or not 201 */ 202 203 public void setRowSumsRight(boolean right) 204 { 205 field_1_wsbool = rowsumsright.setByteBoolean(field_1_wsbool, right); 206 } 207 208 // end bitfields 209 210 /** 211 * set the second byte (see bit setters) 212 */ 213 214 public void setWSBool2(byte bool2) 215 { 216 field_2_wsbool = field_2_wsbool = bool2; 217 } 218 219 // bool2 bitfields 220 221 /** 222 * fit to page option is on 223 * @param fit2page fit or not 224 */ 225 226 public void setFitToPage(boolean fit2page) 227 { 228 field_2_wsbool = fittopage.setByteBoolean(field_2_wsbool, fit2page); 229 } 230 231 /** 232 * set whether to display the guts or not 233 * 234 * @param guts or no guts (or glory) 235 */ 236 237 public void setDisplayGuts(boolean guts) 238 { 239 field_2_wsbool = displayguts.setByteBoolean(field_2_wsbool, guts); 240 } 241 242 /** 243 * whether alternate expression evaluation is on 244 * @param altexp alternative expression evaluation or not 245 */ 246 247 public void setAlternateExpression(boolean altexp) 248 { 249 field_2_wsbool = alternateexpression.setByteBoolean(field_2_wsbool, 250 altexp); 251 } 252 253 /** 254 * whether alternative formula entry is on 255 * @param formula alternative formulas or not 256 */ 257 258 public void setAlternateFormula(boolean formula) 259 { 260 field_2_wsbool = alternateformula.setByteBoolean(field_2_wsbool, 261 formula); 262 } 263 264 // end bitfields 265 266 /** 267 * get first byte (see bit getters) 268 */ 269 270 public byte getWSBool1() 271 { 272 return field_1_wsbool; 273 } 274 275 // bool1 bitfields 276 277 /** 278 * show automatic page breaks or not 279 * @return whether to show auto page breaks 280 */ 281 282 public boolean getAutobreaks() 283 { 284 return autobreaks.isSet(field_1_wsbool); 285 } 286 287 /** 288 * get whether sheet is a dialog sheet or not 289 * @return isDialog or not 290 */ 291 292 public boolean getDialog() 293 { 294 return dialog.isSet(field_1_wsbool); 295 } 296 297 /** 298 * get if row summaries appear below detail in the outline 299 * @return below or not 300 */ 301 302 public boolean getRowSumsBelow() 303 { 304 return rowsumsbelow.isSet(field_1_wsbool); 305 } 306 307 /** 308 * get if col summaries appear right of the detail in the outline 309 * @return right or not 310 */ 311 312 public boolean getRowSumsRight() 313 { 314 return rowsumsright.isSet(field_1_wsbool); 315 } 316 317 // end bitfields 318 319 /** 320 * get the second byte (see bit getters) 321 */ 322 323 public byte getWSBool2() 324 { 325 return field_2_wsbool; 326 } 327 328 // bool2 bitfields 329 330 /** 331 * fit to page option is on 332 * @return fit or not 333 */ 334 335 public boolean getFitToPage() 336 { 337 return fittopage.isSet(field_2_wsbool); 338 } 339 340 /** 341 * get whether to display the guts or not 342 * 343 * @return guts or no guts (or glory) 344 */ 345 346 public boolean getDisplayGuts() 347 { 348 return displayguts.isSet(field_2_wsbool); 349 } 350 351 /** 352 * whether alternate expression evaluation is on 353 * @return alternative expression evaluation or not 354 */ 355 356 public boolean getAlternateExpression() 357 { 358 return alternateexpression.isSet(field_2_wsbool); 359 } 360 361 /** 362 * whether alternative formula entry is on 363 * @return alternative formulas or not 364 */ 365 366 public boolean getAlternateFormula() 367 { 368 return alternateformula.isSet(field_2_wsbool); 369 } 370 371 // end bitfields 372 public String toString() 373 { 374 StringBuffer buffer = new StringBuffer(); 375 376 buffer.append("[WSBOOL]\n"); 377 buffer.append(" .wsbool1 = ") 378 .append(Integer.toHexString(getWSBool1())).append("\n"); 379 buffer.append(" .autobreaks = ").append(getAutobreaks()) 380 .append("\n"); 381 buffer.append(" .dialog = ").append(getDialog()) 382 .append("\n"); 383 buffer.append(" .rowsumsbelw= ").append(getRowSumsBelow()) 384 .append("\n"); 385 buffer.append(" .rowsumsrigt= ").append(getRowSumsRight()) 386 .append("\n"); 387 buffer.append(" .wsbool2 = ") 388 .append(Integer.toHexString(getWSBool2())).append("\n"); 389 buffer.append(" .fittopage = ").append(getFitToPage()) 390 .append("\n"); 391 buffer.append(" .displayguts= ").append(getDisplayGuts()) 392 .append("\n"); 393 buffer.append(" .alternateex= ") 394 .append(getAlternateExpression()).append("\n"); 395 buffer.append(" .alternatefo= ").append(getAlternateFormula()) 396 .append("\n"); 397 buffer.append("[/WSBOOL]\n"); 398 return buffer.toString(); 399 } 400 401 public int serialize(int offset, byte [] data) 402 { 403 LittleEndian.putShort(data, 0 + offset, sid); 404 LittleEndian.putShort(data, 2 + offset, ( short ) 0x2); 405 data[ 5 + offset ] = getWSBool1(); 406 data[ 4 + offset ] = getWSBool2(); 407 return getRecordSize(); 408 } 409 410 public int getRecordSize() 411 { 412 return 6; 413 } 414 415 public short getSid() 416 { 417 return this.sid; 418 } 419 420 public Object clone() { 421 WSBoolRecord rec = new WSBoolRecord(); 422 rec.field_1_wsbool = field_1_wsbool; 423 rec.field_2_wsbool = field_2_wsbool; 424 return rec; 425 } 426 } 427