poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r657135 [2/3] - in /poi/branches/ooxml: ./ src/documentation/ src/documentation/content/xdocs/ src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/record/ src/java/org/apache/poi/hssf/record/aggregates/ src/java/org/apache/poi/...
Date Fri, 16 May 2008 17:08:42 GMT
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/WindowOneRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/WindowOneRecord.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/WindowOneRecord.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/WindowOneRecord.java Fri May 16 10:08:40 2008
@@ -57,8 +57,8 @@
         BitFieldFactory.getInstance(0x20);                                        // display tabs at the bottom
 
     // all the rest are "reserved"
-    private short                 field_6_selected_tab;
-    private short                 field_7_displayed_tab;
+    private int                   field_6_active_sheet;
+    private int                   field_7_first_visible_tab;
     private short                 field_8_num_selected_tabs;
     private short                 field_9_tab_width_ratio;
 
@@ -91,8 +91,8 @@
         field_3_width             = in.readShort();
         field_4_height            = in.readShort();
         field_5_options           = in.readShort();
-        field_6_selected_tab      = in.readShort();
-        field_7_displayed_tab     = in.readShort();
+        field_6_active_sheet      = in.readShort();
+        field_7_first_visible_tab     = in.readShort();
         field_8_num_selected_tabs = in.readShort();
         field_9_tab_width_ratio   = in.readShort();
     }
@@ -202,24 +202,33 @@
 
     // end bitfields
 
+    public void setActiveSheetIndex(int index) {
+    	field_6_active_sheet = index;
+	}
     /**
-     * set the selected tab number
-     * @param s  tab number
+     * deprecated May 2008
+     * @deprecated - Misleading name - use setActiveSheetIndex() 
      */
-
     public void setSelectedTab(short s)
     {
-        field_6_selected_tab = s;
+        setActiveSheetIndex(s);
     }
 
     /**
-     * set the displayed tab number
-     * @param t  tab number
+     * Sets the first visible sheet in the worksheet tab-bar.  This method does <b>not</b>
+     *  hide, select or focus sheets.  It just sets the scroll position in the tab-bar.
+     * @param t the sheet index of the tab that will become the first in the tab-bar
      */
+    public void setFirstVisibleTab(int t) {
+        field_7_first_visible_tab = t;
+    }
 
-    public void setDisplayedTab(short t)
-    {
-        field_7_displayed_tab = t;
+    /**
+     * deprecated May 2008
+     * @deprecated - Misleading name - use setFirstVisibleTab() 
+     */
+    public void setDisplayedTab(short t) {
+        setFirstVisibleTab(t);
     }
 
     /**
@@ -347,24 +356,36 @@
 
     // end options bitfields
 
+    
     /**
-     * get the selected tab number
-     * @return Tab number
+     * @return the index of the currently displayed sheet 
+     */
+    public int getActiveSheetIndex() {
+    	return field_6_active_sheet;
+    }
+    /**
+     * deprecated May 2008
+     * @deprecated - Misleading name - use getActiveSheetIndex() 
      */
-
     public short getSelectedTab()
     {
-        return field_6_selected_tab;
+        return (short) getActiveSheetIndex();
     }
 
     /**
-     * get the displayed tab number
-     * @return Tab number
+     * @return the first visible sheet in the worksheet tab-bar. 
+     * I.E. the scroll position of the tab-bar.
+     */
+    public int getFirstVisibleTab() {
+        return field_7_first_visible_tab;
+    }
+    /**
+     * deprecated May 2008
+     * @deprecated - Misleading name - use getFirstVisibleTab() 
      */
-
     public short getDisplayedTab()
     {
-        return field_7_displayed_tab;
+        return (short) getFirstVisibleTab();
     }
 
     /**
@@ -412,10 +433,10 @@
             .append(getDisplayVerticalScrollbar()).append("\n");
         buffer.append("        .tabs        = ").append(getDisplayTabs())
             .append("\n");
-        buffer.append("    .selectedtab     = ")
-            .append(Integer.toHexString(getSelectedTab())).append("\n");
-        buffer.append("    .displayedtab    = ")
-            .append(Integer.toHexString(getDisplayedTab())).append("\n");
+        buffer.append("    .activeSheet     = ")
+            .append(Integer.toHexString(getActiveSheetIndex())).append("\n");
+        buffer.append("    .firstVisibleTab    = ")
+            .append(Integer.toHexString(getFirstVisibleTab())).append("\n");
         buffer.append("    .numselectedtabs = ")
             .append(Integer.toHexString(getNumSelectedTabs())).append("\n");
         buffer.append("    .tabwidthratio   = ")
@@ -434,8 +455,8 @@
         LittleEndian.putShort(data, 8 + offset, getWidth());
         LittleEndian.putShort(data, 10 + offset, getHeight());
         LittleEndian.putShort(data, 12 + offset, getOptions());
-        LittleEndian.putShort(data, 14 + offset, getSelectedTab());
-        LittleEndian.putShort(data, 16 + offset, getDisplayedTab());
+        LittleEndian.putUShort(data, 14 + offset, getActiveSheetIndex());
+        LittleEndian.putUShort(data, 16 + offset, getFirstVisibleTab());
         LittleEndian.putShort(data, 18 + offset, getNumSelectedTabs());
         LittleEndian.putShort(data, 20 + offset, getTabWidthRatio());
         return getRecordSize();

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/WindowTwoRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/WindowTwoRecord.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/WindowTwoRecord.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/WindowTwoRecord.java Fri May 16 10:08:40 2008
@@ -54,7 +54,7 @@
     private BitField          displayGuts             = BitFieldFactory.getInstance(0x80);
     private BitField          freezePanesNoSplit      = BitFieldFactory.getInstance(0x100);
     private BitField          selected                = BitFieldFactory.getInstance(0x200);
-    private BitField          paged                   = BitFieldFactory.getInstance(0x400);
+    private BitField          active                  = BitFieldFactory.getInstance(0x400);
     private BitField          savedInPageBreakPreview = BitFieldFactory.getInstance(0x800);
 
     // 4-7 reserved
@@ -222,12 +222,16 @@
      * is the sheet currently displayed in the window
      * @param p  displayed or not
      */
-
-    public void setPaged(boolean p)
-    {
-        field_1_options = paged.setShortBoolean(field_1_options, p);
+    public void setActive(boolean p) {
+        field_1_options = active.setShortBoolean(field_1_options, p);
+    }
+    /**
+     * deprecated May 2008
+     * @deprecated use setActive()
+     */
+    public void setPaged(boolean p) {
+    	setActive(p);
     }
-
     /**
      * was the sheet saved in page break view
      * @param p  pagebreaksaved or not
@@ -416,9 +420,15 @@
      * @return displayed or not
      */
 
-    public boolean getPaged()
-    {
-        return paged.isSet(field_1_options);
+    public boolean isActive() {
+        return active.isSet(field_1_options);
+    }
+    /**
+     * deprecated May 2008
+     * @deprecated use isActive()
+     */
+    public boolean getPaged() {
+        return isActive();
     }
 
     /**
@@ -520,7 +530,7 @@
             .append(getFreezePanesNoSplit()).append("\n");
         buffer.append("       .selected    = ").append(getSelected())
             .append("\n");
-        buffer.append("       .paged       = ").append(getPaged())
+        buffer.append("       .active       = ").append(isActive())
             .append("\n");
         buffer.append("       .svdinpgbrkpv= ")
             .append(getSavedInPageBreakPreview()).append("\n");

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java Fri May 16 10:08:40 2008
@@ -35,19 +35,17 @@
  * @author Jason Height (jheight at chariot dot net dot au)
  */
 
-public class RowRecordsAggregate
-    extends Record
-{
-    int     firstrow = -1;
-    int     lastrow  = -1;
-    Map records  = null;
-    int     size     = 0;
+public final class RowRecordsAggregate extends Record {
+    private int     firstrow = -1;
+    private int     lastrow  = -1;
+    private Map records  = null; // TODO - use a proper key in this map
+    private int     size     = 0;
 
     /** Creates a new instance of ValueRecordsAggregate */
 
     public RowRecordsAggregate()
     {
-        records = new TreeMap();
+        records = new TreeMap();  
     }
 
     public void insertRow(RowRecord row)
@@ -74,15 +72,13 @@
         records.remove(row);
     }
 
-    public RowRecord getRow(int rownum)
-    {
-		// Row must be between 0 and 65535
-		if(rownum < 0 || rownum > 65535) {
-			throw new IllegalArgumentException("The row number must be between 0 and 65535");
-		}
+    public RowRecord getRow(int rownum) {
+        // Row must be between 0 and 65535
+        if(rownum < 0 || rownum > 65535) {
+            throw new IllegalArgumentException("The row number must be between 0 and 65535");
+        }
 
-        RowRecord row = new RowRecord();
-        row.setRowNumber(rownum);
+        RowRecord row = new RowRecord(rownum);
         return ( RowRecord ) records.get(row);
     }
 
@@ -333,7 +329,7 @@
 
         // Find the start of the group.
         int startRow = findStartOfRowOutlineGroup( rowNumber );
-        RowRecord rowRecord = (RowRecord) getRow( startRow );
+        RowRecord rowRecord = getRow( startRow );
 
         // Hide all the columns until the end of the group
         int lastRow = writeHidden( rowRecord, startRow, true );
@@ -358,17 +354,8 @@
      * @return RowRecord created for the passed in row number
      * @see org.apache.poi.hssf.record.RowRecord
      */
-    public static RowRecord createRow(int row)
-    {
-        RowRecord rowrec = new RowRecord();
-
-        //rowrec.setRowNumber(( short ) row);
-        rowrec.setRowNumber(row);
-        rowrec.setHeight(( short ) 0xff);
-        rowrec.setOptimize(( short ) 0x0);
-        rowrec.setOptionFlags(( short ) 0x100);  // seems necessary for outlining
-        rowrec.setXFIndex(( short ) 0xf);
-        return rowrec;
+    public static RowRecord createRow(int rowNumber) {
+        return new RowRecord(rowNumber);
     }
 
     public boolean isRowGroupCollapsed( int row )
@@ -399,12 +386,12 @@
         int endIdx = findEndOfRowOutlineGroup( idx );
 
         // expand:
-        // colapsed bit must be unset
+        // collapsed bit must be unset
         // hidden bit gets unset _if_ surrounding groups are expanded you can determine
         //   this by looking at the hidden bit of the enclosing group.  You will have
         //   to look at the start and the end of the current group to determine which
         //   is the enclosing group
-        // hidden bit only is altered for this outline level.  ie.  don't uncollapse contained groups
+        // hidden bit only is altered for this outline level.  ie.  don't un-collapse contained groups
         if ( !isRowGroupHiddenByParent( idx ) )
         {
             for ( int i = startIdx; i <= endIdx; i++ )

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java Fri May 16 10:08:40 2008
@@ -32,18 +32,6 @@
     public final static int  SIZE = 3;
     private int numParams=0;
 
-    /**
-     * FuncPtgs are defined to be 4 bytes but the actual FuncPtg uses only 2 bytes.
-     * If we have leftOvers that are read from the file we should serialize them back out.
-     * <p>
-     * If the leftovers are removed, a prompt "Warning: Data may have been lost occurs in Excel"
-     */
-	//protected byte[] leftOvers = null;
-
-    private FuncPtg() {
-      //Required for clone methods
-    }
-
     /**Creates new function pointer from a byte array
      * usually called while reading an excel file.
      */
@@ -75,11 +63,9 @@
     }
 
     public Object clone() {
-      FuncPtg ptg = new FuncPtg();
-      //ptg.field_1_num_args = field_1_num_args;
-      ptg.field_2_fnc_index = field_2_fnc_index;
-      ptg.setClass(ptgClass);
-     return ptg;
+        FuncPtg ptg = new FuncPtg(field_2_fnc_index);
+        ptg.setClass(ptgClass);
+        return ptg;
     }
 
     public int getSize() {

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/Area2DEval.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/Area2DEval.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/Area2DEval.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/Area2DEval.java Fri May 16 10:08:40 2008
@@ -22,79 +22,11 @@
 
 /**
  * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
- *   
+ * 
  */
-public final class Area2DEval implements AreaEval {
-// TODO -refactor with Area3DEval
-    private final AreaPtg _delegate;
+public final class Area2DEval extends AreaEvalBase {
 
-    private final ValueEval[] _values;
-
-    public Area2DEval(Ptg ptg, ValueEval[] values) {
-        if(ptg == null) {
-            throw new IllegalArgumentException("ptg must not be null");
-        }
-        if(values == null) {
-            throw new IllegalArgumentException("values must not be null");
-        }
-        for(int i=values.length-1; i>=0; i--) {
-            if(values[i] == null) {
-                throw new IllegalArgumentException("value array elements must not be null");
-            }
-        }
-        // TODO - check size of array vs size of AreaPtg
-        _delegate = (AreaPtg) ptg;
-        _values = values;
-    }
-
-    public int getFirstColumn() {
-        return _delegate.getFirstColumn();
-    }
-
-    public int getFirstRow() {
-        return _delegate.getFirstRow();
-    }
-
-    public int getLastColumn() {
-        return _delegate.getLastColumn();
-    }
-
-    public int getLastRow() {
-        return _delegate.getLastRow();
-    }
-
-    public ValueEval[] getValues() {
-        return _values;
-    }
-    
-    public ValueEval getValueAt(int row, int col) {
-        ValueEval retval;
-        int index = ((row-getFirstRow())*(getLastColumn()-getFirstColumn()+1))+(col-getFirstColumn());
-        if (index <0 || index >= _values.length)
-            retval = ErrorEval.VALUE_INVALID;
-        else 
-            retval = _values[index];
-        return retval;
-    }
-    
-    public boolean contains(int row, int col) {
-        return (getFirstRow() <= row) && (getLastRow() >= row) 
-            && (getFirstColumn() <= col) && (getLastColumn() >= col);
-    }
-    
-    public boolean containsRow(int row) {
-        return (getFirstRow() <= row) && (getLastRow() >= row);
-    }
-    
-    public boolean containsColumn(short col) {
-        return (getFirstColumn() <= col) && (getLastColumn() >= col);
-    }
-    
-    public boolean isColumn() {
-        return _delegate.getFirstColumn() == _delegate.getLastColumn();
-    }
-
-    public boolean isRow() {
-        return _delegate.getFirstRow() == _delegate.getLastRow();
-    }
-}
+	public Area2DEval(Ptg ptg, ValueEval[] values) {
+		super((AreaPtg) ptg, values);
+	}
+}
\ No newline at end of file

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/Area3DEval.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/Area3DEval.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/Area3DEval.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/Area3DEval.java Fri May 16 10:08:40 2008
@@ -22,84 +22,18 @@
 
 /**
  * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
- *  
+ * 
  */
-public final class Area3DEval implements AreaEval {
-	// TODO -refactor with Area3DEval
-    private final Area3DPtg _delegate;
+public final class Area3DEval extends AreaEvalBase {
 
-    private final ValueEval[] _values;
+	private final int _externSheetIndex;
 
-    public Area3DEval(Ptg ptg, ValueEval[] values) {
-        if(ptg == null) {
-            throw new IllegalArgumentException("ptg must not be null");
-        }
-        if(values == null) {
-            throw new IllegalArgumentException("values must not be null");
-        }
-        for(int i=values.length-1; i>=0; i--) {
-            if(values[i] == null) {
-                throw new IllegalArgumentException("value array elements must not be null");
-            }
-        }
-        // TODO - check size of array vs size of AreaPtg
-        _values = values;
-        _delegate = (Area3DPtg) ptg;
-    }
-
-    public int getFirstColumn() {
-        return _delegate.getFirstColumn();
-    }
-
-    public int getFirstRow() {
-        return _delegate.getFirstRow();
-    }
-
-    public int getLastColumn() {
-        return (short) _delegate.getLastColumn();
-    }
-
-    public int getLastRow() {
-        return _delegate.getLastRow();
-    }
-
-    public ValueEval[] getValues() {
-        return _values;
-    }
-    
-    public ValueEval getValueAt(int row, int col) {
-        ValueEval retval;
-        int index = (row-getFirstRow())*(col-getFirstColumn());
-        if (index <0 || index >= _values.length)
-            retval = ErrorEval.VALUE_INVALID;
-        else 
-            retval = _values[index];
-        return retval;
-    }
-    
-    public boolean contains(int row, int col) {
-        return (getFirstRow() <= row) && (getLastRow() >= row) 
-            && (getFirstColumn() <= col) && (getLastColumn() >= col);
-    }
-    
-    public boolean containsRow(int row) {
-        return (getFirstRow() <= row) && (getLastRow() >= row);
-    }
-    
-    public boolean containsColumn(short col) {
-        return (getFirstColumn() <= col) && (getLastColumn() >= col);
-    }
-    
-    
-    public boolean isColumn() {
-        return _delegate.getFirstColumn() == _delegate.getLastColumn();
-    }
-
-    public boolean isRow() {
-        return _delegate.getFirstRow() == _delegate.getLastRow();
-    }
-
-    public int getExternSheetIndex() {
-        return _delegate.getExternSheetIndex();
-    }
+	public Area3DEval(Ptg ptg, ValueEval[] values) {
+		super((Area3DPtg) ptg, values);
+		_externSheetIndex = ((Area3DPtg) ptg).getExternSheetIndex();
+	}
+
+	public int getExternSheetIndex() {
+		return _externSheetIndex;
+	}
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadataReader.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadataReader.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadataReader.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/function/FunctionMetadataReader.java Fri May 16 10:08:40 2008
@@ -37,15 +37,14 @@
 final class FunctionMetadataReader {
 
 	private static final String METADATA_FILE_NAME = "functionMetadata.txt";
+	
+	/** plain ASCII text metadata file uses three dots for ellipsis */
+	private static final String ELLIPSIS = "...";
 
 	private static final Pattern TAB_DELIM_PATTERN = Pattern.compile("\t");
 	private static final Pattern SPACE_DELIM_PATTERN = Pattern.compile(" ");
 	private static final byte[] EMPTY_BYTE_ARRAY = { };
 
-	// special characters from the ooo document
-	private static final int CHAR_ELLIPSIS_8230 = 8230;
-	private static final int CHAR_NDASH_8211 = 8211;
-	
 	private static final String[] DIGIT_ENDING_FUNCTION_NAMES = {
 		// Digits at the end of a function might be due to a left-over footnote marker.
 		// except in these cases
@@ -59,10 +58,12 @@
 			throw new RuntimeException("resource '" + METADATA_FILE_NAME + "' not found");
 		}
 
-		BufferedReader br = null;
+		BufferedReader br;
 		try {
 			br = new BufferedReader(new InputStreamReader(is,"UTF-8"));
-		} catch(UnsupportedEncodingException e) { /* never happens */ }
+		} catch(UnsupportedEncodingException e) {
+			throw new RuntimeException(e);
+		}
 		FunctionDataBuilder fdb = new FunctionDataBuilder(400);
 
 		try {
@@ -127,7 +128,9 @@
 		}
 		String[] array = SPACE_DELIM_PATTERN.split(codes);
 		int nItems = array.length;
-		if(array[nItems-1].charAt(0) == CHAR_ELLIPSIS_8230) {
+		if(ELLIPSIS.equals(array[nItems-1])) {
+			// final ellipsis is optional, and ignored
+			// (all unspecified params are assumed to be the same as the last)
 			nItems --;
 		}
 		byte[] result = new byte[nItems];
@@ -141,7 +144,6 @@
 		if(codes.length() == 1) {
 			switch (codes.charAt(0)) {
 				case '-':
-				case CHAR_NDASH_8211: // this is what the ooo doc has
 					return true;
 			}
 		}

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java Fri May 16 10:08:40 2008
@@ -826,8 +826,7 @@
         int row=record.getRow();
         short col=record.getColumn();
         short styleIndex=record.getXFIndex();
-        if ((cellType != CELL_TYPE_ERROR) && (cellType != CELL_TYPE_FORMULA))
-        {
+        if (cellType != CELL_TYPE_ERROR) {
             setCellType(CELL_TYPE_ERROR, false, row, col, styleIndex);
         }
         (( BoolErrRecord ) record).setValue(value);

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java Fri May 16 10:08:40 2008
@@ -21,7 +21,6 @@
 import java.util.NoSuchElementException;
 
 import org.apache.poi.hssf.model.Sheet;
-import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.CellValueRecordInterface;
 import org.apache.poi.hssf.record.RowRecord;
 import org.apache.poi.ss.usermodel.Cell;
@@ -39,11 +38,9 @@
 
     // used for collections
     public final static int INITIAL_CAPACITY = 5;
-    //private short rowNum;
+
     private int rowNum;
     private HSSFCell[] cells=new HSSFCell[INITIAL_CAPACITY];
-//    private short firstcell = -1;
-//    private short lastcell = -1;
 
     /**
      * reference to low level representation
@@ -63,7 +60,8 @@
 
     private Sheet sheet;
 
-    protected HSSFRow()
+    // TODO - ditch this constructor
+    HSSFRow()
     {
     }
 
@@ -75,18 +73,12 @@
      * @param rowNum the row number of this row (0 based)
      * @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int)
      */
-
-    //protected HSSFRow(Workbook book, Sheet sheet, short rowNum)
-    protected HSSFRow(HSSFWorkbook book, Sheet sheet, int rowNum)
+    HSSFRow(HSSFWorkbook book, Sheet sheet, int rowNum)
     {
         this.rowNum = rowNum;
         this.book = book;
         this.sheet = sheet;
-        row = new RowRecord();
-        row.setOptionFlags( (short)0x100 );   // seems necessary for outlining to work.  
-        row.setHeight((short) 0xff);
-        row.setLastCol((short) -1);
-        row.setFirstCol((short) -1);
+        row = new RowRecord(rowNum);
 
         setRowNum(rowNum);
     }
@@ -100,8 +92,7 @@
      * @param record the low level api object this row should represent
      * @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int)
      */
-
-    protected HSSFRow(HSSFWorkbook book, Sheet sheet, RowRecord record)
+    HSSFRow(HSSFWorkbook book, Sheet sheet, RowRecord record)
     {
         this.book = book;
         this.sheet = sheet;
@@ -219,12 +210,11 @@
      * @param rowNum  the row number (0-based)
      * @throws IndexOutOfBoundsException if the row number is not within the range 0-65535.
      */
-
-    //public void setRowNum(short rowNum)
-    public void setRowNum(int rowNum)
-    {
-        if ((rowNum < 0) || (rowNum > RowRecord.MAX_ROW_NUMBER))
-          throw new IndexOutOfBoundsException("Row number must be between 0 and "+RowRecord.MAX_ROW_NUMBER+", was <"+rowNum+">");
+    public void setRowNum(int rowNum) {
+        if ((rowNum < 0) || (rowNum > RowRecord.MAX_ROW_NUMBER)) {
+          throw new IllegalArgumentException("Invalid row number (" + rowNum 
+                  + ") outside allowable range (0.." + RowRecord.MAX_ROW_NUMBER + ")");
+        }
         this.rowNum = rowNum;
         if (row != null)
         {
@@ -236,8 +226,6 @@
      * get row number this row represents
      * @return the row number (0 based)
      */
-
-    //public short getRowNum()
     public int getRowNum()
     {
         return rowNum;

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Fri May 16 10:08:40 2008
@@ -153,6 +153,7 @@
     {
         int sloc = sheet.getLoc();
         RowRecord row = sheet.getNextRow();
+        boolean rowRecordsAlreadyPresent = row!=null;
 
         while (row != null)
         {
@@ -177,6 +178,18 @@
             if ( ( lastrow == null ) || ( lastrow.getRowNum() != cval.getRow() ) )
             {
                 hrow = getRow( cval.getRow() );
+                if (hrow == null) {
+                    // Some tools (like Perl module Spreadsheet::WriteExcel - bug 41187) skip the RowRecords 
+                    // Excel, OpenOffice.org and GoogleDocs are all OK with this, so POI should be too.
+                    if (rowRecordsAlreadyPresent) {
+                        // if at least one row record is present, all should be present.
+                        throw new RuntimeException("Unexpected missing row when some rows already present");
+                    }
+                    // create the row record on the fly now.
+                    RowRecord rowRec = new RowRecord(cval.getRow());
+                    sheet.addRow(rowRec);
+                    hrow = createRowFromRecord(rowRec);
+                }
             }
             if ( hrow != null )
             {
@@ -983,12 +996,33 @@
     }
 
     /**
+     * Note - this is not the same as whether the sheet is focused (isActive)
+     * @return <code>true</code> if this sheet is currently selected
+     */
+    public boolean isSelected() {
+        return getSheet().getWindowTwo().getSelected();
+    }
+    /**
      * Sets whether sheet is selected.
      * @param sel Whether to select the sheet or deselect the sheet.
      */
     public void setSelected( boolean sel )
     {
-        getSheet().setSelected( sel );
+        getSheet().getWindowTwo().setSelected(sel);
+    }
+    /**
+     * @return <code>true</code> if this sheet is currently focused
+     */
+    public boolean isActive() {
+        return getSheet().getWindowTwo().isActive();
+    }
+    /**
+     * Sets whether sheet is selected.
+     * @param sel Whether to select the sheet or deselect the sheet.
+     */
+    public void setActive(boolean sel )
+    {
+        getSheet().getWindowTwo().setActive(sel);
     }
 
     /**
@@ -1690,6 +1724,23 @@
      * @param column the column index
      */
     public void autoSizeColumn(short column) {
+    	autoSizeColumn(column, false);
+    }
+    
+    /**
+     * Adjusts the column width to fit the contents.
+     *
+     * This process can be relatively slow on large sheets, so this should
+     *  normally only be called once per column, at the end of your
+     *  processing.
+     *
+     * You can specify whether the content of merged cells should be considered or ignored.  
+     *  Default is to ignore merged cells.
+     *   
+     * @param column the column index
+     * @param useMergedCells whether to use the contents of merged cells when calculating the width of the column
+     */
+    public void autoSizeColumn(short column, boolean useMergedCells) {
         AttributedString str;
         TextLayout layout;
         /**
@@ -1698,13 +1749,13 @@
          * '0' looks to be a good choice.
          */
         char defaultChar = '0';
-
+       
         /**
          * This is the multiple that the font height is scaled by when determining the
          * boundary of rotated text.
          */
         double fontHeightMultiple = 2.0;
-
+       
         FontRenderContext frc = new FontRenderContext(null, true, true);
 
         HSSFWorkbook wb = new HSSFWorkbook(book);
@@ -1716,21 +1767,27 @@
         int defaultCharWidth = (int)layout.getAdvance();
 
         double width = -1;
+        rows:
         for (Iterator it = rowIterator(); it.hasNext();) {
             HSSFRow row = (HSSFRow) it.next();
             HSSFCell cell = row.getCell(column);
 
-            boolean isCellInMergedRegion = false;
-            for (int i = 0 ; i < getNumMergedRegions() && ! isCellInMergedRegion; i++) {
-                isCellInMergedRegion = getMergedRegionAt(i).contains(row.getRowNum(), column);
-            }
+            if (cell == null) continue;
 
-            if (cell == null | isCellInMergedRegion) continue;
+            int colspan = 1;
+            for (int i = 0 ; i < getNumMergedRegions(); i++) {
+                if (getMergedRegionAt(i).contains(row.getRowNum(), column)) {
+                	if (!useMergedCells) {
+                    	// If we're not using merged cells, skip this one and move on to the next. 
+                		continue rows;
+                	}
+                	cell = row.getCell(getMergedRegionAt(i).getColumnFrom());
+                	colspan = 1+ getMergedRegionAt(i).getColumnTo() - getMergedRegionAt(i).getColumnFrom();
+                }
+            }
 
             HSSFCellStyle style = cell.getCellStyle();
             HSSFFont font = wb.getFontAt(style.getFontIndex());
-            //the number of spaces to indent the text in the cell
-            int indention = style.getIndention();
 
             if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
                 HSSFRichTextString rt = cell.getRichStringCellValue();
@@ -1763,9 +1820,9 @@
                         trans.concatenate(
                         AffineTransform.getScaleInstance(1, fontHeightMultiple)
                         );
-                        width = Math.max(width, layout.getOutline(trans).getBounds().getWidth() / defaultCharWidth + indention);
+                        width = Math.max(width, ((layout.getOutline(trans).getBounds().getWidth() / colspan) / defaultCharWidth) + cell.getCellStyle().getIndention());
                     } else {
-                        width = Math.max(width, layout.getBounds().getWidth() / defaultCharWidth + indention);
+                        width = Math.max(width, ((layout.getBounds().getWidth() / colspan) / defaultCharWidth) + cell.getCellStyle().getIndention());
                     }
                 }
             } else {
@@ -1808,19 +1865,19 @@
                         trans.concatenate(
                         AffineTransform.getScaleInstance(1, fontHeightMultiple)
                         );
-                        width = Math.max(width, layout.getOutline(trans).getBounds().getWidth() / defaultCharWidth + indention);
+                        width = Math.max(width, ((layout.getOutline(trans).getBounds().getWidth() / colspan) / defaultCharWidth) + cell.getCellStyle().getIndention());
                     } else {
-                        width = Math.max(width, layout.getBounds().getWidth() / defaultCharWidth + indention);
+                        width = Math.max(width, ((layout.getBounds().getWidth() / colspan) / defaultCharWidth) + cell.getCellStyle().getIndention());
                     }
                 }
             }
 
-            if (width != -1) {
-                if (width > Short.MAX_VALUE) { //calculated width can be greater that Short.MAX_VALUE!
-                     width = Short.MAX_VALUE;
-                }
-                sheet.setColumnWidth(column, (short) (width * 256));
+        }
+        if (width != -1) {
+            if (width > Short.MAX_VALUE) { //width can be bigger that Short.MAX_VALUE!
+            	width = Short.MAX_VALUE;
             }
+            sheet.setColumnWidth(column, (short) (width * 256));
         }
     }
 

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java Fri May 16 10:08:40 2008
@@ -382,16 +382,66 @@
         workbook.setSheetOrder(sheetname, pos);
     }
 
+    private void validateSheetIndex(int index) {
+        int lastSheetIx = sheets.size() - 1;
+        if (index < 0 || index > lastSheetIx) {
+            throw new IllegalArgumentException("Sheet index (" 
+                    + index +") is out of range (0.." +    lastSheetIx + ")");
+        }
+    }
+    
     /**
-     * sets the tab whose data is actually seen when the sheet is opened.
-     * This may be different from the "selected sheet" since excel seems to
-     * allow you to show the data of one sheet when another is seen "selected"
-     * in the tabs (at the bottom).
-     * @see org.apache.poi.hssf.usermodel.HSSFSheet#setSelected(boolean)
-     * @param index
+     * Selects a single sheet. This may be different to
+     * the 'active' sheet (which is the sheet with focus).  
+     */
+    public void setSelectedTab(int index) {
+        
+        validateSheetIndex(index);
+        int nSheets = sheets.size();
+        for (int i=0; i<nSheets; i++) {
+               getSheetAt(i).setSelected(i == index);
+        }
+        workbook.getWindowOne().setNumSelectedTabs((short)1);
+    }
+    /**
+     * deprecated May 2008
+     * @deprecated use setSelectedTab(int)
      */
     public void setSelectedTab(short index) {
-        workbook.getWindowOne().setSelectedTab(index);
+        setSelectedTab((int)index);
+    }
+    public void setSelectedTabs(int[] indexes) {
+        
+        for (int i = 0; i < indexes.length; i++) {
+            validateSheetIndex(indexes[i]);
+        }
+        int nSheets = sheets.size();
+        for (int i=0; i<nSheets; i++) {
+            boolean bSelect = false;
+            for (int j = 0; j < indexes.length; j++) {
+                if (indexes[j] == i) {
+                    bSelect = true;
+                    break;
+                }
+                
+            }
+               getSheetAt(i).setSelected(bSelect);
+        }
+        workbook.getWindowOne().setNumSelectedTabs((short)indexes.length);
+    }
+    /**
+     * Convenience method to set the active sheet.  The active sheet is is the sheet
+     * which is currently displayed when the workbook is viewed in Excel.
+     * 'Selected' sheet(s) is a distinct concept.
+     */
+    public void setActiveSheet(int index) {
+        
+        validateSheetIndex(index);
+        int nSheets = sheets.size();
+        for (int i=0; i<nSheets; i++) {
+             getSheetAt(i).setActive(i == index);
+        }
+        workbook.getWindowOne().setActiveSheetIndex(index);
     }
 
     /**
@@ -401,25 +451,46 @@
      * in the tabs (at the bottom).
      * @see org.apache.poi.hssf.usermodel.HSSFSheet#setSelected(boolean)
      */
+    public int getActiveSheetIndex() {
+        return workbook.getWindowOne().getActiveSheetIndex();
+    }
+    /**
+     * deprecated May 2008
+     * @deprecated - Misleading name - use getActiveSheetIndex() 
+     */
     public short getSelectedTab() {
-        return workbook.getWindowOne().getSelectedTab();
+        return (short) getActiveSheetIndex();
     }
 
+    
     /**
      * sets the first tab that is displayed in the list of tabs
      * in excel.
      * @param index
      */
+    public void setFirstVisibleTab(int index) {
+        workbook.getWindowOne().setFirstVisibleTab(index);
+    }
+    /**
+     * deprecated May 2008
+     * @deprecated - Misleading name - use setFirstVisibleTab() 
+     */
     public void setDisplayedTab(short index) {
-        workbook.getWindowOne().setDisplayedTab(index);
+       setFirstVisibleTab(index);
     }
 
     /**
-     * sets the first tab that is displayed in the list of tabs
-     * in excel.
+     * sets the first tab that is displayed in the list of tabs in excel.
+     */
+    public int getFirstVisibleTab() {
+        return workbook.getWindowOne().getFirstVisibleTab();
+    }
+    /**
+     * deprecated May 2008
+     * @deprecated - Misleading name - use getFirstVisibleTab() 
      */
     public short getDisplayedTab() {
-        return workbook.getWindowOne().getDisplayedTab();
+        return (short) getFirstVisibleTab();
     }
 
     /**
@@ -580,17 +651,13 @@
 
     public HSSFSheet createSheet()
     {
-
-//        if (getNumberOfSheets() == 3)
-//            throw new RuntimeException("You cannot have more than three sheets in HSSF 1.0");
         HSSFSheet sheet = new HSSFSheet(this);
 
         sheets.add(sheet);
-        workbook.setSheetName(sheets.size() - 1,
-                "Sheet" + (sheets.size() - 1));
-        WindowTwoRecord windowTwo = (WindowTwoRecord) sheet.getSheet().findFirstRecordBySid(WindowTwoRecord.sid);
-        windowTwo.setSelected(sheets.size() == 1);
-        windowTwo.setPaged(sheets.size() == 1);
+        workbook.setSheetName(sheets.size() - 1, "Sheet" + (sheets.size() - 1));
+        boolean isOnlySheet = sheets.size() == 1;
+        sheet.setSelected(isOnlySheet);
+        sheet.setActive(isOnlySheet);
         return sheet;
     }
 
@@ -601,23 +668,24 @@
      */
 
     public HSSFSheet cloneSheet(int sheetNum) {
-      HSSFSheet srcSheet = (HSSFSheet)sheets.get(sheetNum);
-      String srcName = workbook.getSheetName(sheetNum);
-      if (srcSheet != null) {
+        validateSheetIndex(sheetNum);
+        HSSFSheet srcSheet = (HSSFSheet) sheets.get(sheetNum);
+        String srcName = workbook.getSheetName(sheetNum);
         HSSFSheet clonedSheet = srcSheet.cloneSheet(this);
-        WindowTwoRecord windowTwo = (WindowTwoRecord) clonedSheet.getSheet().findFirstRecordBySid(WindowTwoRecord.sid);
-        windowTwo.setSelected(sheets.size() == 1);
-        windowTwo.setPaged(sheets.size() == 1);
+        clonedSheet.setSelected(false);
+        clonedSheet.setActive(false);
 
         sheets.add(clonedSheet);
-        int i=1;
+        int i = 1;
         while (true) {
-            //Try and find the next sheet name that is unique
+            // Try and find the next sheet name that is unique
             String name = srcName;
             String index = Integer.toString(i++);
-            if (name.length()+index.length()+2<31)
-              name = name + "("+index+")";
-            else name = name.substring(0, 31-index.length()-2)+"("+index+")";
+            if (name.length() + index.length() + 2 < 31) {
+                name = name + "(" + index + ")";
+            } else {
+                name = name.substring(0, 31 - index.length() - 2) + "(" + index + ")";
+            }
 
             //If the sheet name is unique, then set it otherwise move on to the next number.
             if (workbook.getSheetIndex(name) == -1) {
@@ -626,18 +694,18 @@
             }
         }
         return clonedSheet;
-      }
-      return null;
     }
 
     /**
-     * create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns
-     * the high level representation.  Use this to create new sheets.
-     *
-     * @param sheetname     sheetname to set for the sheet.
+     * create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and
+     * returns the high level representation. Use this to create new sheets.
+     * 
+     * @param sheetname
+     *            sheetname to set for the sheet.
      * @return HSSFSheet representing the new sheet.
-     * @throws IllegalArgumentException if there is already a sheet present with a case-insensitive
-     *  match for the specified name.
+     * @throws IllegalArgumentException
+     *             if there is already a sheet present with a case-insensitive
+     *             match for the specified name.
      */
 
     public HSSFSheet createSheet(String sheetname)
@@ -649,9 +717,9 @@
 
         sheets.add(sheet);
         workbook.setSheetName(sheets.size() - 1, sheetname);
-        WindowTwoRecord windowTwo = (WindowTwoRecord) sheet.getSheet().findFirstRecordBySid(WindowTwoRecord.sid);
-        windowTwo.setSelected(sheets.size() == 1);
-        windowTwo.setPaged(sheets.size() == 1);
+        boolean isOnlySheet = sheets.size() == 1;
+        sheet.setSelected(isOnlySheet);
+        sheet.setActive(isOnlySheet);
         return sheet;
     }
 
@@ -855,8 +923,7 @@
         HSSFPrintSetup printSetup = sheet.getPrintSetup();
         printSetup.setValidSettings(false);
 
-        WindowTwoRecord w2 = (WindowTwoRecord) sheet.getSheet().findFirstRecordBySid(WindowTwoRecord.sid);
-        w2.setPaged(true);
+        sheet.setActive(true);
     }
 
     private NameRecord findExistingRowColHeaderNameRecord( int sheetIndex )

Modified: poi/branches/ooxml/src/java/org/apache/poi/poifs/storage/BlockListImpl.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/poifs/storage/BlockListImpl.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/poifs/storage/BlockListImpl.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/poifs/storage/BlockListImpl.java Fri May 16 10:08:40 2008
@@ -102,7 +102,8 @@
         catch (ArrayIndexOutOfBoundsException ignored)
         {
             throw new IOException("Cannot remove block[ " + index
-                                  + " ]; out of range");
+                                  + " ]; out of range[ 0 - " + 
+                                  (_blocks.length-1) + " ]");
         }
         return result;
     }

Modified: poi/branches/ooxml/src/java/org/apache/poi/poifs/storage/RawDataBlock.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/poifs/storage/RawDataBlock.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/poifs/storage/RawDataBlock.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/poifs/storage/RawDataBlock.java Fri May 16 10:08:40 2008
@@ -81,8 +81,9 @@
             log.log(POILogger.ERROR,
             		"Unable to read entire block; " + count
                      + type + " read before EOF; expected "
-                     + blockSize + " bytes. Your document"
-                     + " has probably been truncated!"
+                     + blockSize + " bytes. Your document "
+                     + "was either written by software that "
+                     + "ignores the spec, or has been truncated!"
             );
         }
         else {

Modified: poi/branches/ooxml/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java Fri May 16 10:08:40 2008
@@ -220,8 +220,7 @@
                     cell.setCellValue(cv.getBooleanValue());
                     break;
                 case Cell.CELL_TYPE_ERROR:
-                    cell.setCellType(Cell.CELL_TYPE_ERROR);
-                    cell.setCellValue(cv.getErrorValue());
+                    cell.setCellErrorValue(cv.getErrorValue());
                     break;
                 case Cell.CELL_TYPE_NUMERIC:
                     cell.setCellType(Cell.CELL_TYPE_NUMERIC);

Modified: poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Cell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Cell.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Cell.java (original)
+++ poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Cell.java Fri May 16 10:08:40 2008
@@ -78,9 +78,11 @@
     int getCellType();
     short getCellNum();
 
-    byte getErrorCellValue();
     String getCellFormula();
 
+    byte getErrorCellValue();
+    void setCellErrorValue(byte value);
+
     HSSFCellStyle getCellStyle();
 
     boolean getBooleanCellValue();

Modified: poi/branches/ooxml/src/records/definitions/pane_record.xml
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/records/definitions/pane_record.xml?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/records/definitions/pane_record.xml (original)
+++ poi/branches/ooxml/src/records/definitions/pane_record.xml Fri May 16 10:08:40 2008
@@ -31,7 +31,7 @@
             <const name="lower right" value="0"/>
             <const name="upper right" value="1"/>
             <const name="lower left" value="2"/>
-            <const name="uper left" value="3"/>
+            <const name="upper left" value="3"/>
         </field>
     </fields>
 </record>

Modified: poi/branches/ooxml/src/resources/main/org/apache/poi/hssf/record/formula/function/functionMetadata-asGenerated.txt
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/resources/main/org/apache/poi/hssf/record/formula/function/functionMetadata-asGenerated.txt?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/resources/main/org/apache/poi/hssf/record/formula/function/functionMetadata-asGenerated.txt (original)
+++ poi/branches/ooxml/src/resources/main/org/apache/poi/hssf/record/formula/function/functionMetadata-asGenerated.txt Fri May 16 10:08:40 2008
@@ -29,7 +29,7 @@
 7	MAX	1	30	V	R		
 8	ROW	0	1	V	R		
 9	COLUMN	0	1	V	R		
-10	NA	0	0	V	–		
+10	NA	0	0	V	-		
 11	NPV	2	30	V	V R		
 12	STDEV	1	30	V	R		
 13	DOLLAR	1	2	V	V V		
@@ -38,7 +38,7 @@
 16	COS	1	1	V	V		
 17	TAN	1	1	V	V		
 18	ARCTAN	1	1	V	V		
-19	PI	0	0	V	–		
+19	PI	0	0	V	-		
 20	SQRT	1	1	V	V		
 21	EXP	1	1	V	V		
 22	LN	1	1	V	V		
@@ -53,8 +53,8 @@
 31	MID	3	3	V	V V V		
 32	LEN	1	1	V	V		
 33	VALUE	1	1	V	V		
-34	TRUE	0	0	V	–		
-35	FALSE	0	0	V	–		
+34	TRUE	0	0	V	-		
+35	FALSE	0	0	V	-		
 36	AND	1	30	V	R		
 37	OR	1	30	V	R		
 38	NOT	1	1	V	V		
@@ -80,7 +80,7 @@
 60	RATE	3	6	V	V V V V V V		
 61	MIRR	3	3	V	R V V		
 62	IRR	1	2	V	R V		
-63	RAND	0	0	V	–	x	
+63	RAND	0	0	V	-	x	
 64	MATCH	2	3	V	V R R		
 65	DATE	3	3	V	V V V		
 66	TIME	3	3	V	V V V		
@@ -91,7 +91,7 @@
 71	HOUR	1	1	V	V		
 72	MINUTE	1	1	V	V		
 73	SECOND	1	1	V	V		
-74	NOW	0	0	V	–	x	
+74	NOW	0	0	V	-	x	
 75	AREAS	1	1	V	R		
 76	ROWS	1	1	V	R		
 77	COLUMNS	1	1	V	R		
@@ -170,10 +170,10 @@
 215	JIS	1	1	V	V		x
 219	ADDRESS	2	5	V	V V V V V		
 220	DAYS360	2	2	V	V V		x
-221	TODAY	0	0	V	–	x	
+221	TODAY	0	0	V	-	x	
 222	VDB	5	7	V	V V V V V V V		
-227	MEDIAN	1	30	V	R …		
-228	SUMPRODUCT	1	30	V	A …		
+227	MEDIAN	1	30	V	R ...		
+228	SUMPRODUCT	1	30	V	A ...		
 229	SINH	1	1	V	V		
 230	COSH	1	1	V	V		
 231	TANH	1	1	V	V		
@@ -188,7 +188,7 @@
 247	DB	4	5	V	V V V V V		
 252	FREQUENCY	2	2	A	R R		
 261	ERROR.TYPE	1	1	V	V		
-269	AVEDEV	1	30	V	R …		
+269	AVEDEV	1	30	V	R ...		
 270	BETADIST	3	5	V	V V V V V		
 271	GAMMALN	1	1	V	V		
 272	BETAINV	3	5	V	V V V V V		
@@ -237,12 +237,12 @@
 315	SLOPE	2	2	V	A A		
 316	TTEST	4	4	V	A A V V		
 317	PROB	3	4	V	A A V V		
-318	DEVSQ	1	30	V	R …		
-319	GEOMEAN	1	30	V	R …		
-320	HARMEAN	1	30	V	R …		
-321	SUMSQ	0	30	V	R …		
-322	KURT	1	30	V	R …		
-323	SKEW	1	30	V	R …		
+318	DEVSQ	1	30	V	R ...		
+319	GEOMEAN	1	30	V	R ...		
+320	HARMEAN	1	30	V	R ...		
+321	SUMSQ	0	30	V	R ...		
+322	KURT	1	30	V	R ...		
+323	SKEW	1	30	V	R ...		
 324	ZTEST	2	3	V	R V V		
 325	LARGE	2	2	V	R V		
 326	SMALL	2	2	V	R V		
@@ -274,10 +274,10 @@
 358	GETPIVOTDATA	2	30				
 359	HYPERLINK	1	2	V	V V		
 360	PHONETIC	1	1	V	R		
-361	AVERAGEA	1	30	V	R …		
-362	MAXA	1	30	V	R …		
-363	MINA	1	30	V	R …		
-364	STDEVPA	1	30	V	R …		
-365	VARPA	1	30	V	R …		
-366	STDEVA	1	30	V	R …		
-367	VARA	1	30	V	R …		
+361	AVERAGEA	1	30	V	R ...		
+362	MAXA	1	30	V	R ...		
+363	MINA	1	30	V	R ...		
+364	STDEVPA	1	30	V	R ...		
+365	VARPA	1	30	V	R ...		
+366	STDEVA	1	30	V	R ...		
+367	VARA	1	30	V	R ...		

Modified: poi/branches/ooxml/src/resources/main/org/apache/poi/hssf/record/formula/function/functionMetadata.txt
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/resources/main/org/apache/poi/hssf/record/formula/function/functionMetadata.txt?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/resources/main/org/apache/poi/hssf/record/formula/function/functionMetadata.txt (original)
+++ poi/branches/ooxml/src/resources/main/org/apache/poi/hssf/record/formula/function/functionMetadata.txt Fri May 16 10:08:40 2008
@@ -31,7 +31,7 @@
 7	MAX	1	30	V	R		
 8	ROW	0	1	V	R		
 9	COLUMN	0	1	V	R		
-10	NA	0	0	V	–		
+10	NA	0	0	V	-		
 11	NPV	2	30	V	V R		
 12	STDEV	1	30	V	R		
 13	DOLLAR	1	2	V	V V		
@@ -40,7 +40,7 @@
 16	COS	1	1	V	V		
 17	TAN	1	1	V	V		
 18	ATAN	1	1	V	V		
-19	PI	0	0	V	–		
+19	PI	0	0	V	-		
 20	SQRT	1	1	V	V		
 21	EXP	1	1	V	V		
 22	LN	1	1	V	V		
@@ -55,8 +55,8 @@
 31	MID	3	3	V	V V V		
 32	LEN	1	1	V	V		
 33	VALUE	1	1	V	V		
-34	TRUE	0	0	V	–		
-35	FALSE	0	0	V	–		
+34	TRUE	0	0	V	-		
+35	FALSE	0	0	V	-		
 36	AND	1	30	V	R		
 37	OR	1	30	V	R		
 38	NOT	1	1	V	V		
@@ -82,7 +82,7 @@
 60	RATE	3	6	V	V V V V V V		
 61	MIRR	3	3	V	R V V		
 62	IRR	1	2	V	R V		
-63	RAND	0	0	V	–	x	
+63	RAND	0	0	V	-	x	
 64	MATCH	2	3	V	V R R		
 65	DATE	3	3	V	V V V		
 66	TIME	3	3	V	V V V		
@@ -93,7 +93,7 @@
 71	HOUR	1	1	V	V		
 72	MINUTE	1	1	V	V		
 73	SECOND	1	1	V	V		
-74	NOW	0	0	V	–	x	
+74	NOW	0	0	V	-	x	
 75	AREAS	1	1	V	R		
 76	ROWS	1	1	V	R		
 77	COLUMNS	1	1	V	R		
@@ -172,10 +172,10 @@
 215	JIS	1	1	V	V		x
 219	ADDRESS	2	5	V	V V V V V		
 220	DAYS360	2	2	V	V V		x
-221	TODAY	0	0	V	–	x	
+221	TODAY	0	0	V	-	x	
 222	VDB	5	7	V	V V V V V V V		
-227	MEDIAN	1	30	V	R …		
-228	SUMPRODUCT	1	30	V	A …		
+227	MEDIAN	1	30	V	R ...		
+228	SUMPRODUCT	1	30	V	A ...		
 229	SINH	1	1	V	V		
 230	COSH	1	1	V	V		
 231	TANH	1	1	V	V		
@@ -192,7 +192,7 @@
 247	DB	4	5	V	V V V V V		
 252	FREQUENCY	2	2	A	R R		
 261	ERROR.TYPE	1	1	V	V		
-269	AVEDEV	1	30	V	R …		
+269	AVEDEV	1	30	V	R ...		
 270	BETADIST	3	5	V	V V V V V		
 271	GAMMALN	1	1	V	V		
 272	BETAINV	3	5	V	V V V V V		
@@ -241,12 +241,12 @@
 315	SLOPE	2	2	V	A A		
 316	TTEST	4	4	V	A A V V		
 317	PROB	3	4	V	A A V V		
-318	DEVSQ	1	30	V	R …		
-319	GEOMEAN	1	30	V	R …		
-320	HARMEAN	1	30	V	R …		
-321	SUMSQ	0	30	V	R …		
-322	KURT	1	30	V	R …		
-323	SKEW	1	30	V	R …		
+318	DEVSQ	1	30	V	R ...		
+319	GEOMEAN	1	30	V	R ...		
+320	HARMEAN	1	30	V	R ...		
+321	SUMSQ	0	30	V	R ...		
+322	KURT	1	30	V	R ...		
+323	SKEW	1	30	V	R ...		
 324	ZTEST	2	3	V	R V V		
 325	LARGE	2	2	V	R V		
 326	SMALL	2	2	V	R V		
@@ -278,10 +278,10 @@
 358	GETPIVOTDATA	2	30				
 359	HYPERLINK	1	2	V	V V		
 360	PHONETIC	1	1	V	R		
-361	AVERAGEA	1	30	V	R …		
-362	MAXA	1	30	V	R …		
-363	MINA	1	30	V	R …		
-364	STDEVPA	1	30	V	R …		
-365	VARPA	1	30	V	R …		
-366	STDEVA	1	30	V	R …		
-367	VARA	1	30	V	R …		
+361	AVERAGEA	1	30	V	R ...		
+362	MAXA	1	30	V	R ...		
+363	MINA	1	30	V	R ...		
+364	STDEVPA	1	30	V	R ...		
+365	VARPA	1	30	V	R ...		
+366	STDEVA	1	30	V	R ...		
+367	VARA	1	30	V	R ...		

Modified: poi/branches/ooxml/src/scratchpad/examples/src/org/apache/poi/hslf/examples/DataExtraction.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/examples/src/org/apache/poi/hslf/examples/DataExtraction.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/examples/src/org/apache/poi/hslf/examples/DataExtraction.java (original)
+++ poi/branches/ooxml/src/scratchpad/examples/src/org/apache/poi/hslf/examples/DataExtraction.java Fri May 16 10:08:40 2008
@@ -69,16 +69,9 @@
                     String name = ole.getInstanceName();
                     if ("Worksheet".equals(name)) {
 
-                        //save xls on disk
-                        FileOutputStream out = new FileOutputStream(name + "-("+(j)+").xls");
-                        InputStream dis = data.getData();
-                        byte[] chunk = new byte[2048];
-                        int count;
-                        while ((count = dis.read(chunk)) >= 0) {
-                          out.write(chunk,0,count);
-                        }
-                        is.close();
-                        out.close();
+                        //read xls
+                        HSSFWorkbook wb = new HSSFWorkbook(data.getData());
+
                     } else if ("Document".equals(name)) {
                         HWPFDocument doc = new HWPFDocument(data.getData());
                         //read the word document
@@ -93,7 +86,15 @@
                         doc.write(out);
                         out.close();
                      }  else {
-                        System.err.println("Processing " + name);
+                        FileOutputStream out = new FileOutputStream(ole.getProgID() + "-"+(j+1)+".dat");
+                        InputStream dis = data.getData();
+                        byte[] chunk = new byte[2048];
+                        int count;
+                        while ((count = dis.read(chunk)) >= 0) {
+                          out.write(chunk,0,count);
+                        }
+                        is.close();
+                        out.close();
                     }
                 }
 

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/ShapeFactory.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/ShapeFactory.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/ShapeFactory.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/ShapeFactory.java Fri May 16 10:08:40 2008
@@ -76,6 +76,7 @@
             case ShapeTypes.TextBox:
                 shape = new TextBox(spContainer, parent);
                 break;
+            case ShapeTypes.HostControl: 
             case ShapeTypes.PictureFrame: {
                 EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(spContainer, EscherOptRecord.RECORD_ID);
                 EscherProperty prop = Shape.getEscherProperty(opt, EscherProperties.BLIP__PICTUREID);

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java Fri May 16 10:08:40 2008
@@ -45,7 +45,6 @@
 	protected TextBytesAtom  _byteAtom;
 	protected TextCharsAtom  _charAtom;
 	protected StyleTextPropAtom _styleAtom;
-    protected TextSpecInfoAtom  _specAtom;
 	protected boolean _isUnicode;
 	protected RichTextRun[] _rtRuns;
 	private SlideShow slideShow;
@@ -319,9 +318,9 @@
 	 *  touch the stylings. 
 	 */
 	private void storeText(String s) {
-		// Remove a single trailing \n, as there is an implicit one at the
+		// Remove a single trailing \r, as there is an implicit one at the
 		//  end of every record
-		if(s.endsWith("\n")) {
+		if(s.endsWith("\r")) {
 			s = s.substring(0, s.length()-1);
 		}
 		
@@ -361,6 +360,18 @@
 				_isUnicode = true;
 			}
 		}
+        /**
+         * If TextSpecInfoAtom is present, we must update the text size in it,
+         * otherwise the ppt will be corrupted
+         */
+        if(_records != null) for (int i = 0; i < _records.length; i++) {
+            if(_records[i] instanceof TextSpecInfoAtom){
+                TextSpecInfoAtom specAtom = (TextSpecInfoAtom)_records[i];
+                if((s.length() + 1) != specAtom.getCharactersCovered()){
+                    specAtom.reset(s.length() + 1);
+                }
+            }
+        }
 	}
 	
 	/**
@@ -446,7 +457,7 @@
 	 *  as the the first character has. 
 	 * If you care about styling, do setText on a RichTextRun instead 
 	 */
-	public synchronized void setText(String s) {
+	public synchronized void setRawText(String s) {
 		// Save the new text to the atoms
 		storeText(s);
 		RichTextRun fst = _rtRuns[0];
@@ -474,20 +485,18 @@
 			_rtRuns[0] = new RichTextRun(this,0,s.length());
 		}
 
-        /**
-         * If TextSpecInfoAtom is present, we must update the text size,
-         * otherwise the ppt will be corrupted
-         */
-        if(_records != null) for (int i = 0; i < _records.length; i++) {
-            if(_records[i] instanceof TextSpecInfoAtom){
-                TextSpecInfoAtom specAtom = (TextSpecInfoAtom)_records[i];
-                specAtom.setTextSize(s.length());
-            }
-
-        }
 	}
 
-	/**
+    /**
+     * Changes the text.
+     * Converts '\r' into '\n'
+     */
+    public synchronized void setText(String s) {
+        String text = normalize(s);
+        setRawText(text);
+    }
+
+    /**
 	 * Ensure a StyleTextPropAtom is present for this run, 
 	 *  by adding if required. Normally for internal TextRun use.
 	 */
@@ -666,4 +675,12 @@
         return null;
 
     }
+
+    /**
+     * Returns a new string with line breaks converted into internal ppt representation
+     */
+    public String normalize(String s){
+        String ns = s.replaceAll("\\r?\\n", "\r");
+        return ns;
+    }
 }

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java Fri May 16 10:08:40 2008
@@ -36,7 +36,7 @@
     private byte[] _header;
 
     // Links to our more interesting children
-    private ExEmbedAtom embedAtom;
+    private RecordAtom embedAtom;
     private ExOleObjAtom oleObjAtom;
     private CString menuName;
     private CString progId;
@@ -91,11 +91,7 @@
     private void findInterestingChildren() {
 
         // First child should be the ExHyperlinkAtom
-        if(_children[0] instanceof ExEmbedAtom) {
-            embedAtom = (ExEmbedAtom)_children[0];
-        } else {
-            logger.log(POILogger.ERROR, "First child record wasn't a ExEmbedAtom, was of type " + _children[0].getRecordType());
-        }
+        embedAtom = getEmbedAtom(_children);
 
         // Second child should be the ExOleObjAtom
         if (_children[1] instanceof ExOleObjAtom) {
@@ -115,6 +111,16 @@
         }
     }
 
+    protected RecordAtom getEmbedAtom(Record[] children){
+        RecordAtom atom = null;
+        if(_children[0] instanceof ExEmbedAtom) {
+            atom = (ExEmbedAtom)_children[0];
+        } else {
+            logger.log(POILogger.ERROR, "First child record wasn't a ExEmbedAtom, was of type " + _children[0].getRecordType());
+        }
+        return atom;
+    }
+
     /**
      * Gets the {@link ExEmbedAtom}.
      *
@@ -122,7 +128,7 @@
      */
     public ExEmbedAtom getExEmbedAtom()
     {
-        return embedAtom;
+        return (ExEmbedAtom)embedAtom;
     }
 
     /**

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjStg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjStg.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjStg.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjStg.java Fri May 16 10:08:40 2008
@@ -17,11 +17,9 @@
 
 package org.apache.poi.hslf.record;
 
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
+import java.io.*;
 import java.util.zip.InflaterInputStream;
+import java.util.zip.DeflaterOutputStream;
 
 import org.apache.poi.util.LittleEndian;
 
@@ -93,6 +91,25 @@
     }
 
     /**
+     * Sets the embedded data.
+     *
+     * @param data the embedded data.
+     */
+     public void setData(byte[] data) throws IOException {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        //first four bytes is the length of the raw data
+        byte[] b = new byte[4];
+        LittleEndian.putInt(b, data.length);
+        out.write(b);
+
+        DeflaterOutputStream def = new DeflaterOutputStream(out);
+        def.write(data, 0, data.length);
+        def.finish();
+        _data = out.toByteArray();
+        LittleEndian.putInt(_header, 4, _data.length);
+    }
+
+    /**
      * Gets the record type.
      *
      * @return the record type.

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java Fri May 16 10:08:40 2008
@@ -119,7 +119,7 @@
     public static final Type RecolorInfoAtom = new Type(4071,null);
     public static final Type ExQuickTimeMovie = new Type(4074,null);
     public static final Type ExQuickTimeMovieData = new Type(4075,null);
-    public static final Type ExControl = new Type(4078,null);
+    public static final Type ExControl = new Type(4078,ExControl.class);
     public static final Type SlideListWithText = new Type(4080,SlideListWithText.class);
     public static final Type InteractiveInfo = new Type(4082,InteractiveInfo.class);
     public static final Type InteractiveInfoAtom = new Type(4083,InteractiveInfoAtom.class);

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java Fri May 16 10:08:40 2008
@@ -20,6 +20,7 @@
 
 import java.io.OutputStream;
 import java.io.IOException;
+import java.util.ArrayList;
 
 /**
  * The special info runs contained in this text.
@@ -82,4 +83,118 @@
     public void setTextSize(int size){
         LittleEndian.putInt(_data, 0, size);
     }
+
+    /**
+     * Reset the content to one info run with the default values
+     * @param size  the site of parent text
+     */
+    public void reset(int size){
+        _data = new byte[10];
+        // 01 00 00 00
+        LittleEndian.putInt(_data, 0, size);
+        // 01 00 00 00
+        LittleEndian.putInt(_data, 4, 1); //mask
+        // 00 00
+        LittleEndian.putShort(_data, 8, (short)0); //langId
+
+        // Update the size (header bytes 5-8)
+        LittleEndian.putInt(_header, 4, _data.length);
+    }
+
+    /**
+     * Get the number of characters covered by this records
+     *
+     * @return the number of characters covered by this records
+     */
+    public int getCharactersCovered(){
+        int covered = 0;
+        TextSpecInfoRun[] runs = getTextSpecInfoRuns();
+        for (int i = 0; i < runs.length; i++) covered += runs[i].len;
+        return covered;
+    }
+
+    public TextSpecInfoRun[] getTextSpecInfoRuns(){
+        ArrayList lst = new ArrayList();
+        int pos = 0;
+        int[] bits = {1, 0, 2};
+        while(pos < _data.length) {
+            TextSpecInfoRun run = new TextSpecInfoRun();
+            run.len = LittleEndian.getInt(_data, pos); pos += 4;
+            run.mask = LittleEndian.getInt(_data, pos); pos += 4;
+            for (int i = 0; i < bits.length; i++) {
+                if((run.mask & 1 << bits[i]) != 0){
+                    switch (bits[i]){
+                        case 0:
+                            run.spellInfo = LittleEndian.getShort(_data, pos); pos += 2;
+                            break;
+                        case 1:
+                            run.langId = LittleEndian.getShort(_data, pos); pos += 2;
+                            break;
+                        case 2:
+                            run.altLangId = LittleEndian.getShort(_data, pos); pos += 2;
+                            break;
+                    }
+                }
+            }
+            lst.add(run);
+        }
+        return (TextSpecInfoRun[])lst.toArray(new TextSpecInfoRun[lst.size()]);
+
+    }
+
+    public static class TextSpecInfoRun {
+        //Length of special info run.
+        protected int len;
+
+        //Special info mask of this run;
+        protected int mask;
+
+        // info fields as indicated by the mask.
+        // -1 means the bit is not set
+        protected short spellInfo = -1;
+        protected short langId = -1;
+        protected short altLangId = -1;
+
+        /**
+         * Spelling status of this text. See Spell Info table below.
+         *
+         * <p>Spell Info Types:</p>
+         * <li>0    Unchecked
+         * <li>1    Previously incorrect, needs rechecking
+         * <li>2    Correct
+         * <li>3    Incorrect
+         *
+         * @return Spelling status of this text
+         */
+        public short getSpellInfo(){
+            return spellInfo;
+        }
+
+        /**
+         * Windows LANGID for this text.
+         *
+         * @return Windows LANGID for this text.
+         */
+        public short getLangId(){
+            return spellInfo;
+        }
+
+        /**
+         * Alternate Windows LANGID of this text;
+         * must be a valid non-East Asian LANGID if the text has an East Asian language,
+         * otherwise may be an East Asian LANGID or language neutral (zero).
+         *
+         * @return  Alternate Windows LANGID of this text
+         */
+        public short getAltLangId(){
+            return altLangId;
+        }
+
+        /**
+         * @return Length of special info run.
+         */
+        public int length(){
+            return len;
+        }
+    }
 }

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/ObjectData.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/ObjectData.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/ObjectData.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/ObjectData.java Fri May 16 10:08:40 2008
@@ -17,6 +17,7 @@
 package org.apache.poi.hslf.usermodel;
 
 import java.io.InputStream;
+import java.io.IOException;
 
 import org.apache.poi.hslf.record.ExOleObjStg;
 
@@ -50,6 +51,15 @@
     }
 
     /**
+     * Sets the embedded data.
+     *
+     * @param data the embedded data.
+     */
+     public void setData(byte[] data) throws IOException {
+        storage.setData(data);    
+    }
+
+    /**
      * Return the record that contains the object data.
      *
      * @return the record that contains the object data.

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java Fri May 16 10:08:40 2008
@@ -162,10 +162,18 @@
 	 * Change the text
 	 */
 	public void setText(String text) {
-		length = text.length();
-		parentRun.changeTextInRichTextRun(this,text);
+        String s = parentRun.normalize(text);
+        setRawText(s);
 	}
 	
+    /**
+     * Change the text
+     */
+    public void setRawText(String text) {
+        length = text.length();
+        parentRun.changeTextInRichTextRun(this,text);
+    }
+
 	/**
 	 * Tells the RichTextRun its new position in the parent TextRun
 	 * @param startAt

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java Fri May 16 10:08:40 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -16,22 +15,20 @@
    limitations under the License.
 ==================================================================== */
 
-
 package org.apache.poi.hwpf.model;
 
+import java.util.Arrays;
+
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.LittleEndian;
 
-import org.apache.poi.hwpf.usermodel.CharacterProperties;
-import org.apache.poi.hwpf.usermodel.ParagraphProperties;
-
-import org.apache.poi.hwpf.sprm.ParagraphSprmCompressor;
-import org.apache.poi.hwpf.sprm.CharacterSprmCompressor;
-
-import java.util.Arrays;
-
-public class ListLevel
+/**
+ * 
+ */
+public final class ListLevel
 {
+  private static final int RGBXCH_NUMS_SIZE = 9;
+
   private int _iStartAt;
   private byte _nfc;
   private byte _info;
@@ -70,7 +67,7 @@
     _grpprlPapx = new byte[0];
     _grpprlChpx = new byte[0];
     _numberText = new char[0];
-    _rgbxchNums = new byte[9];
+    _rgbxchNums = new byte[RGBXCH_NUMS_SIZE];
 
     if (numbered)
     {
@@ -90,12 +87,11 @@
     _nfc = buf[offset++];
     _info = buf[offset++];
 
-    _rgbxchNums = new byte[9];
-    for (int x = 0; x < 9; x++)
-    {
-      _rgbxchNums[x] = buf[offset++];
-    }
-    _ixchFollow = buf[offset++];
+    _rgbxchNums = new byte[RGBXCH_NUMS_SIZE];
+    System.arraycopy(buf, offset, _rgbxchNums, 0, RGBXCH_NUMS_SIZE);
+    offset += RGBXCH_NUMS_SIZE;
+  
+   _ixchFollow = buf[offset++];
     _dxaSpace = LittleEndian.getInt(buf, offset);
     offset += LittleEndian.INT_SIZE;
     _dxaIndent = LittleEndian.getInt(buf, offset);
@@ -207,8 +203,8 @@
     offset += LittleEndian.INT_SIZE;
     buf[offset++] = _nfc;
     buf[offset++] = _info;
-    System.arraycopy(_rgbxchNums, 0, buf, offset, _rgbxchNums.length);
-    offset += _rgbxchNums.length;
+    System.arraycopy(_rgbxchNums, 0, buf, offset, RGBXCH_NUMS_SIZE);
+    offset += RGBXCH_NUMS_SIZE;
     buf[offset++] = _ixchFollow;
     LittleEndian.putInt(buf, offset, _dxaSpace);
     offset += LittleEndian.INT_SIZE;
@@ -225,23 +221,33 @@
     System.arraycopy(_grpprlPapx, 0, buf, offset, _cbGrpprlPapx);
     offset += _cbGrpprlPapx;
 
-    LittleEndian.putShort(buf, offset, (short)_numberText.length);
-    offset += LittleEndian.SHORT_SIZE;
-    for (int x = 0; x < _numberText.length; x++)
-    {
-      LittleEndian.putShort(buf, offset, (short)_numberText[x]);
+    if (_numberText == null) {
+      // TODO - write junit to test this flow
+      LittleEndian.putUShort(buf, offset, 0);
+    } else {
+      LittleEndian.putUShort(buf, offset, _numberText.length);
       offset += LittleEndian.SHORT_SIZE;
+      for (int x = 0; x < _numberText.length; x++)
+      {
+        LittleEndian.putUShort(buf, offset, _numberText[x]);
+        offset += LittleEndian.SHORT_SIZE;
+      }
     }
     return buf;
   }
   public int getSizeInBytes()
   {
-      if (_numberText!=null)
-      {
-            return 28 + _cbGrpprlChpx + _cbGrpprlPapx + (_numberText.length * LittleEndian.SHORT_SIZE) + 2;
-      } else {
-          return 28 + _cbGrpprlChpx + _cbGrpprlPapx  + 2;
-      }
+    int result =
+        6 // int byte byte
+        + RGBXCH_NUMS_SIZE
+        + 13 // byte int int byte byte short
+        + _cbGrpprlChpx 
+        + _cbGrpprlPapx
+        + 2; // numberText length
+    if (_numberText != null) {
+      result += _numberText.length * LittleEndian.SHORT_SIZE;
+    }
+    return result;
   }
 
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/HSSFTests.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/HSSFTests.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/HSSFTests.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/HSSFTests.java Fri May 16 10:08:40 2008
@@ -22,9 +22,7 @@
 
 import org.apache.poi.hssf.eventmodel.TestEventRecordFactory;
 import org.apache.poi.hssf.eventmodel.TestModelFactory;
-import org.apache.poi.hssf.model.TestDrawingManager;
-import org.apache.poi.hssf.model.TestFormulaParser;
-import org.apache.poi.hssf.model.TestSheet;
+import org.apache.poi.hssf.model.AllModelTests;
 import org.apache.poi.hssf.record.AllRecordTests;
 import org.apache.poi.hssf.usermodel.AllUserModelTests;
 import org.apache.poi.hssf.util.TestAreaReference;
@@ -50,10 +48,10 @@
         TestSuite suite = new TestSuite("Tests for org.apache.poi.hssf");
         // $JUnit-BEGIN$
 
+        suite.addTest(AllModelTests.suite());
         suite.addTest(AllUserModelTests.suite());
         suite.addTest(AllRecordTests.suite());
 
-        suite.addTest(new TestSuite(TestFormulaParser.class));
         suite.addTest(new TestSuite(TestAreaReference.class));
         suite.addTest(new TestSuite(TestCellReference.class));
         suite.addTest(new TestSuite(TestRangeAddress.class));
@@ -61,8 +59,6 @@
         suite.addTest(new TestSuite(TestSheetReferences.class));
         suite.addTest(new TestSuite(TestEventRecordFactory.class));
         suite.addTest(new TestSuite(TestModelFactory.class));
-        suite.addTest(new TestSuite(TestDrawingManager.class));
-        suite.addTest(new TestSuite(TestSheet.class));
         // $JUnit-END$
         return suite;
     }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheet.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheet.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheet.java Fri May 16 10:08:40 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,7 +14,6 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.model;
 
@@ -34,8 +32,7 @@
  *
  * @author Glen Stampoultzis (glens at apache.org)
  */
-public class TestSheet extends TestCase
-{
+public final class TestSheet extends TestCase {
     public void testCreateSheet() throws Exception
     {
         // Check we're adding row and cell aggregates
@@ -76,6 +73,21 @@
         if ((regionsToAdd % 1027) != 0)
             recordsExpected++;
         assertTrue("The " + regionsToAdd + " merged regions should have been spread out over " + recordsExpected + " records, not " + recordsAdded, recordsAdded == recordsExpected);
+        // Check we can't add one with invalid date
+        try {
+            sheet.addMergedRegion(10, (short)10, 9, (short)12);
+            fail("Expected an exception to occur");
+        } catch(IllegalArgumentException e) {
+            // occurs during successful test
+            assertEquals("The 'to' row (9) must not be less than the 'from' row (10)", e.getMessage());
+        }
+        try {
+            sheet.addMergedRegion(10, (short)10, 12, (short)9);
+            fail("Expected an exception to occur");
+        } catch(IllegalArgumentException e) {
+            // occurs during successful test
+            assertEquals("The 'to' col (9) must not be less than the 'from' col (10)", e.getMessage());
+        }
     }
 
     public void testRemoveMergedRegion()
@@ -113,9 +125,9 @@
 
         MergeCellsRecord merged = new MergeCellsRecord();
         merged.addArea(0, (short)0, 1, (short)2);
-        records.add(new RowRecord());
-        records.add(new RowRecord());
-        records.add(new RowRecord());
+        records.add(new RowRecord(0));
+        records.add(new RowRecord(1));
+        records.add(new RowRecord(2));
         records.add(merged);
 
         Sheet sheet = Sheet.createSheet(records, 0);
@@ -142,20 +154,11 @@
      */
     public void testRowAggregation() {
         List records = new ArrayList();
-        RowRecord row = new RowRecord();
-        row.setRowNumber(0);
-        records.add(row);
-
-        row = new RowRecord();
-        row.setRowNumber(1);
-        records.add(row);
 
+        records.add(new RowRecord(0));
+        records.add(new RowRecord(1));
         records.add(new StringRecord());
-
-        row = new RowRecord();
-        row.setRowNumber(2);
-        records.add(row);
-
+        records.add(new RowRecord(2));
 
         Sheet sheet = Sheet.createSheet(records, 0);
         assertNotNull("Row [2] was skipped", sheet.getRow(2));
@@ -197,9 +200,9 @@
         Iterator iterator = sheet.getRowBreaks();
         while (iterator.hasNext()) {
             PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-            int main = (int)breakItem.main;
+            int main = breakItem.main;
             if (main != 0 && main != 10 && main != 11) fail("Invalid page break");
-            if (main == 0) 	is0 = true;
+            if (main == 0)     is0 = true;
             if (main == 10) is10= true;
             if (main == 11) is11 = true;
         }
@@ -216,8 +219,6 @@
         assertFalse("row should be removed", sheet.isRowBroken(10));
 
         assertEquals("no more breaks", 0, sheet.getNumRowBreaks());
-
-
     }
 
     /**
@@ -256,10 +257,10 @@
         Iterator iterator = sheet.getColumnBreaks();
         while (iterator.hasNext()) {
             PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-            int main = (int)breakItem.main;
+            int main = breakItem.main;
             if (main != 0 && main != 1 && main != 10 && main != 15) fail("Invalid page break");
-            if (main == 0) 	is0 = true;
-            if (main == 1) 	is1 = true;
+            if (main == 0)  is0 = true;
+            if (main == 1)  is1 = true;
             if (main == 10) is10= true;
             if (main == 15) is15 = true;
         }
@@ -286,72 +287,69 @@
      * works as designed.
      */
     public void testXFIndexForColumn() {
-        try{
-            final short TEST_IDX = 10;
-            final short DEFAULT_IDX = 0xF; // 15
-            short xfindex = Short.MIN_VALUE;
-            Sheet sheet = Sheet.createSheet();
-            
-            // without ColumnInfoRecord
-            xfindex = sheet.getXFIndexForColAt((short) 0);
-            assertEquals(DEFAULT_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 1);
-            assertEquals(DEFAULT_IDX, xfindex);
-            
-            ColumnInfoRecord nci = ( ColumnInfoRecord ) sheet.createColInfo();
-            sheet.columns.insertColumn(nci);
-            
-            // single column ColumnInfoRecord
-            nci.setFirstColumn((short) 2);
-            nci.setLastColumn((short) 2);
-            nci.setXFIndex(TEST_IDX);            
-            xfindex = sheet.getXFIndexForColAt((short) 0);
-            assertEquals(DEFAULT_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 1);
-            assertEquals(DEFAULT_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 2);
-            assertEquals(TEST_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 3);
-            assertEquals(DEFAULT_IDX, xfindex);
-
-            // ten column ColumnInfoRecord
-            nci.setFirstColumn((short) 2);
-            nci.setLastColumn((short) 11);
-            nci.setXFIndex(TEST_IDX);            
-            xfindex = sheet.getXFIndexForColAt((short) 1);
-            assertEquals(DEFAULT_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 2);
-            assertEquals(TEST_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 6);
-            assertEquals(TEST_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 11);
-            assertEquals(TEST_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 12);
-            assertEquals(DEFAULT_IDX, xfindex);
-
-            // single column ColumnInfoRecord starting at index 0
-            nci.setFirstColumn((short) 0);
-            nci.setLastColumn((short) 0);
-            nci.setXFIndex(TEST_IDX);            
-            xfindex = sheet.getXFIndexForColAt((short) 0);
-            assertEquals(TEST_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 1);
-            assertEquals(DEFAULT_IDX, xfindex);
-
-            // ten column ColumnInfoRecord starting at index 0
-            nci.setFirstColumn((short) 0);
-            nci.setLastColumn((short) 9);
-            nci.setXFIndex(TEST_IDX);            
-            xfindex = sheet.getXFIndexForColAt((short) 0);
-            assertEquals(TEST_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 7);
-            assertEquals(TEST_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 9);
-            assertEquals(TEST_IDX, xfindex);
-            xfindex = sheet.getXFIndexForColAt((short) 10);
-            assertEquals(DEFAULT_IDX, xfindex);
-        }
-        catch(Exception e){e.printStackTrace();fail(e.getMessage());}
+        final short TEST_IDX = 10;
+        final short DEFAULT_IDX = 0xF; // 15
+        short xfindex = Short.MIN_VALUE;
+        Sheet sheet = Sheet.createSheet();
+        
+        // without ColumnInfoRecord
+        xfindex = sheet.getXFIndexForColAt((short) 0);
+        assertEquals(DEFAULT_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 1);
+        assertEquals(DEFAULT_IDX, xfindex);
+        
+        ColumnInfoRecord nci = ( ColumnInfoRecord ) sheet.createColInfo();
+        sheet.columns.insertColumn(nci);
+        
+        // single column ColumnInfoRecord
+        nci.setFirstColumn((short) 2);
+        nci.setLastColumn((short) 2);
+        nci.setXFIndex(TEST_IDX);            
+        xfindex = sheet.getXFIndexForColAt((short) 0);
+        assertEquals(DEFAULT_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 1);
+        assertEquals(DEFAULT_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 2);
+        assertEquals(TEST_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 3);
+        assertEquals(DEFAULT_IDX, xfindex);
+
+        // ten column ColumnInfoRecord
+        nci.setFirstColumn((short) 2);
+        nci.setLastColumn((short) 11);
+        nci.setXFIndex(TEST_IDX);            
+        xfindex = sheet.getXFIndexForColAt((short) 1);
+        assertEquals(DEFAULT_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 2);
+        assertEquals(TEST_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 6);
+        assertEquals(TEST_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 11);
+        assertEquals(TEST_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 12);
+        assertEquals(DEFAULT_IDX, xfindex);
+
+        // single column ColumnInfoRecord starting at index 0
+        nci.setFirstColumn((short) 0);
+        nci.setLastColumn((short) 0);
+        nci.setXFIndex(TEST_IDX);            
+        xfindex = sheet.getXFIndexForColAt((short) 0);
+        assertEquals(TEST_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 1);
+        assertEquals(DEFAULT_IDX, xfindex);
+
+        // ten column ColumnInfoRecord starting at index 0
+        nci.setFirstColumn((short) 0);
+        nci.setLastColumn((short) 9);
+        nci.setXFIndex(TEST_IDX);            
+        xfindex = sheet.getXFIndexForColAt((short) 0);
+        assertEquals(TEST_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 7);
+        assertEquals(TEST_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 9);
+        assertEquals(TEST_IDX, xfindex);
+        xfindex = sheet.getXFIndexForColAt((short) 10);
+        assertEquals(DEFAULT_IDX, xfindex);
     }
-
 }
+



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message