You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2008/04/16 00:47:43 UTC

svn commit: r648444 [2/3] - in /poi/branches/ooxml: ./ src/documentation/content/xdocs/ src/java/org/apache/poi/hssf/dev/ src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/record/ src/java/org/apache/poi/hssf/record/formula/ src/java/org...

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=648444&r1=648443&r2=648444&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 Tue Apr 15 15:47:30 2008
@@ -118,7 +118,7 @@
     private int                      cellType;
     private HSSFRichTextString       stringValue;
     private short                    encoding = ENCODING_UNCHANGED;
-    private Workbook                 book;
+    private HSSFWorkbook             book;
     private Sheet                    sheet;
     private CellValueRecordInterface record;
     private HSSFComment              comment;
@@ -141,7 +141,7 @@
      */
 
     //protected HSSFCell(Workbook book, Sheet sheet, short row, short col)
-    protected HSSFCell(Workbook book, Sheet sheet, int row, short col)
+    protected HSSFCell(HSSFWorkbook book, Sheet sheet, int row, short col)
     {
         checkBounds(col);
         stringValue  = null;
@@ -170,7 +170,7 @@
      */
 
     //protected HSSFCell(Workbook book, Sheet sheet, short row, short col,
-    protected HSSFCell(Workbook book, Sheet sheet, int row, short col,
+    protected HSSFCell(HSSFWorkbook book, Sheet sheet, int row, short col,
                        int type)
     {
         checkBounds(col);
@@ -193,7 +193,7 @@
      */
 
     //protected HSSFCell(Workbook book, Sheet sheet, short row,
-    protected HSSFCell(Workbook book, Sheet sheet, int row,
+    protected HSSFCell(HSSFWorkbook book, Sheet sheet, int row,
                        CellValueRecordInterface cval)
     {
         record      = cval;
@@ -204,7 +204,7 @@
         switch (cellType)
         {
             case CELL_TYPE_STRING :
-                stringValue = new HSSFRichTextString(book, (LabelSSTRecord ) cval);
+                stringValue = new HSSFRichTextString(book.getWorkbook(), (LabelSSTRecord ) cval);
                 break;
 
             case CELL_TYPE_BLANK :
@@ -214,7 +214,7 @@
                 stringValue=new HSSFRichTextString(((FormulaRecordAggregate) cval).getStringValue());
                 break;
         }
-        ExtendedFormatRecord xf = book.getExFormatAt(cval.getXFIndex());
+        ExtendedFormatRecord xf = book.getWorkbook().getExFormatAt(cval.getXFIndex());
 
         setCellStyle(new HSSFCellStyle(( short ) cval.getXFIndex(), xf, book));
     }
@@ -270,7 +270,7 @@
      * @return
      */
     protected Workbook getBoundWorkbook() {
-    	return book;
+    	return book.getWorkbook();
     }
 
     /**
@@ -416,9 +416,9 @@
 //                      jmh                        {
 //                      jmh                            str.setUncompressedUnicode();
 //                      jmh                        }
-                        sst = book.addSSTString(str);
+                        sst = book.getWorkbook().addSSTString(str);
                         lrec.setSSTIndex(sst);
-                        getRichStringCellValue().setUnicodeString(book.getSSTString(sst));
+                        getRichStringCellValue().setUnicodeString(book.getWorkbook().getSSTString(sst));
                     }
                 }
                 record = lrec;
@@ -545,7 +545,7 @@
      */
     public void setCellValue(Date value)
     {
-        setCellValue(HSSFDateUtil.getExcelDate(value, this.book.isUsing1904DateWindowing()));
+        setCellValue(HSSFDateUtil.getExcelDate(value, this.book.getWorkbook().isUsing1904DateWindowing()));
     }
 
     /**
@@ -565,7 +565,7 @@
      */
     public void setCellValue(Calendar value)
     {
-        setCellValue( HSSFDateUtil.getExcelDate(value, this.book.isUsing1904DateWindowing()) );
+        setCellValue( HSSFDateUtil.getExcelDate(value, this.book.getWorkbook().isUsing1904DateWindowing()) );
     }
 
     /**
@@ -623,11 +623,11 @@
         int index = 0;
 
         UnicodeString str = hvalue.getUnicodeString();
-        index = book.addSSTString(str);
+        index = book.getWorkbook().addSSTString(str);
         (( LabelSSTRecord ) record).setSSTIndex(index);
         stringValue = hvalue;
-        stringValue.setWorkbookReferences(book, (( LabelSSTRecord ) record));
-        stringValue.setUnicodeString(book.getSSTString(index));
+        stringValue.setWorkbookReferences(book.getWorkbook(), (( LabelSSTRecord ) record));
+        stringValue.setUnicodeString(book.getWorkbook().getSSTString(index));
     }
 
     public void setCellFormula(String formula) {
@@ -737,7 +737,7 @@
                 "You cannot get a date value from an error cell");
         }
         double value=this.getNumericCellValue();
-        if (book.isUsing1904DateWindowing()) {
+        if (book.getWorkbook().isUsing1904DateWindowing()) {
             return HSSFDateUtil.getJavaDate(value,true);
         }
         else {
@@ -922,7 +922,7 @@
     public HSSFCellStyle getCellStyle()
     {
       short styleIndex=record.getXFIndex();
-      ExtendedFormatRecord xf = book.getExFormatAt(styleIndex);
+      ExtendedFormatRecord xf = book.getWorkbook().getExFormatAt(styleIndex);
       return new HSSFCellStyle(styleIndex, xf, book);
     }
 

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java Tue Apr 15 15:47:30 2008
@@ -16,7 +16,6 @@
 ==================================================================== */
 package org.apache.poi.hssf.usermodel;
 
-import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.CFHeaderRecord;
 import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
@@ -50,52 +49,46 @@
  * To create a new Conditional Formatting set use the following approach:
  * 
  * <PRE>
+ * 
+ * // Define a Conditional Formatting rule, which triggers formatting
+ * // when cell's value is greater or equal than 100.0 and
+ * // applies patternFormatting defined below.
+ * HSSFConditionalFormattingRule rule = sheet.createConditionalFormattingRule(
+ *     ComparisonOperator.GE, 
+ *     "100.0", // 1st formula 
+ *     null     // 2nd formula is not used for comparison operator GE
+ * );
+ * 
  * // Create pattern with red background
- * HSSFPatternFormatting patternFormatting = new HSSFPatternFormatting();
+ * HSSFPatternFormatting patternFmt = rule.cretePatternFormatting();
  * patternFormatting.setFillBackgroundColor(HSSFColor.RED.index);
  * 
+ * // Define a region containing first column
  * Region [] regions =
  * {
- *     // Define a region containing first column
  *     new Region(1,(short)1,-1,(short)1)
  * };
  *     
- * HSSFConditionalFormattingRule[] rules = 
- * {
- *     // Define a Conditional Formatting rule, which triggers formatting
- *     // when cell's value is greater or equal than 100.0 and
- *     // applies patternFormatting defined above.
- *         
- *     sheet.createConditionalFormattingRule(
- *             HSSFConditionalFormattingRule.COMPARISON_OPERATOR_GE, 
- *             "100.0", // 1st formula 
- *             null,    // 2nd formula is not used for comparison operator GE
- *             null,    // do not override Font Formatting
- *             null,    // do not override Border Formatting
- *             patternFormatting
- *     )
- * };
- *     
- * // Apply Conditional Formatting rules defined above to the regions  
- * sheet.addConditionalFormatting(regions, rules);
+ * // Apply Conditional Formatting rule defined above to the regions  
+ * sheet.addConditionalFormatting(regions, rule);
  * </PRE>
  * 
  * @author Dmitriy Kumshayev
  */
 public final class HSSFConditionalFormatting
 {
-	private final Workbook workbook;
+	private final HSSFWorkbook _workbook;
 	private final CFRecordsAggregate cfAggregate;
 
-	HSSFConditionalFormatting(HSSFSheet sheet, CFRecordsAggregate cfAggregate)
+	HSSFConditionalFormatting(HSSFWorkbook workbook, CFRecordsAggregate cfAggregate)
 	{
-		if(sheet == null) {
-			throw new IllegalArgumentException("sheet must not be null");
+		if(workbook == null) {
+			throw new IllegalArgumentException("workbook must not be null");
 		}
 		if(cfAggregate == null) {
 			throw new IllegalArgumentException("cfAggregate must not be null");
 		}
-		workbook = sheet.workbook.getWorkbook();
+		_workbook = workbook;
 		this.cfAggregate = cfAggregate;
 	}
 	CFRecordsAggregate getCFRecordsAggregate() {
@@ -141,7 +134,7 @@
 	public HSSFConditionalFormattingRule getRule(int idx)
 	{
 		CFRuleRecord ruleRecord = cfAggregate.getRule(idx);
-		return new HSSFConditionalFormattingRule(workbook, ruleRecord);
+		return new HSSFConditionalFormattingRule(_workbook, ruleRecord);
 	}
 
 	/**

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java Tue Apr 15 15:47:30 2008
@@ -18,7 +18,6 @@
 package org.apache.poi.hssf.usermodel;
 
 import org.apache.poi.hssf.model.FormulaParser;
-import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator;
 import org.apache.poi.hssf.record.cf.BorderFormatting;
@@ -40,33 +39,36 @@
     private static final byte CELL_COMPARISON = CFRuleRecord.CONDITION_TYPE_CELL_VALUE_IS;
 
 	private final CFRuleRecord cfRuleRecord;
-	private final Workbook workbook;
+	private final HSSFWorkbook workbook;
 
-	HSSFConditionalFormattingRule(Workbook pWorkbook, CFRuleRecord pRuleRecord) {
+	HSSFConditionalFormattingRule(HSSFWorkbook pWorkbook, CFRuleRecord pRuleRecord) {
 		workbook = pWorkbook;
 		cfRuleRecord = pRuleRecord;
 	}
-	HSSFConditionalFormattingRule(Workbook pWorkbook, CFRuleRecord pRuleRecord, 
-			HSSFFontFormatting fontFmt, HSSFBorderFormatting bordFmt, HSSFPatternFormatting patternFmt) {
-		this(pWorkbook, pRuleRecord);
-		setFontFormatting(fontFmt);
-		setBorderFormatting(bordFmt);
-		setPatternFormatting(patternFmt);
-	}
 
 	CFRuleRecord getCfRuleRecord()
 	{
 		return cfRuleRecord;
 	}
 	
-	
-	/**
-	 * @param fontFmt pass <code>null</code> to signify 'font unchanged'
-	 */
-	public void setFontFormatting(HSSFFontFormatting fontFmt)
+	private HSSFFontFormatting getFontFormatting(boolean create)
 	{
-		FontFormatting block = fontFmt==null ? null : fontFmt.getFontFormattingBlock();
-		cfRuleRecord.setFontFormatting(block);
+		FontFormatting fontFormatting = cfRuleRecord.getFontFormatting();
+		if ( fontFormatting != null) 
+		{
+			cfRuleRecord.setFontFormatting(fontFormatting);
+			return new HSSFFontFormatting(cfRuleRecord);
+		}
+		else if( create )
+		{
+			fontFormatting = new FontFormatting();
+			cfRuleRecord.setFontFormatting(fontFormatting);
+			return new HSSFFontFormatting(cfRuleRecord);
+		}
+		else
+		{
+			return null;
+		}
 	}
 	
 	/**
@@ -74,50 +76,89 @@
 	 */
 	public HSSFFontFormatting getFontFormatting()
 	{
-		FontFormatting ff = cfRuleRecord.getFontFormatting();
-		if ( ff == null ) {
-			return null;
-		}
-		return new HSSFFontFormatting(ff);
+		return getFontFormatting(false);
 	}
-	
 	/**
-	 * @param borderFmt pass <code>null</code> to signify 'border unchanged'
+	 * create a new font formatting structure if it does not exist, 
+	 * otherwise just return existing object.
+	 * @return - font formatting object, never returns <code>null</code>. 
 	 */
-	public void setBorderFormatting(HSSFBorderFormatting borderFmt)
+	public HSSFFontFormatting createFontFormatting()
+	{
+		return getFontFormatting(true);
+	}
+	
+	private HSSFBorderFormatting getBorderFormatting(boolean create)
 	{
-		BorderFormatting block = borderFmt==null ? null : borderFmt.getBorderFormattingBlock();
-		cfRuleRecord.setBorderFormatting(block);
+		BorderFormatting borderFormatting = cfRuleRecord.getBorderFormatting();
+		if ( borderFormatting != null) 
+		{
+			cfRuleRecord.setBorderFormatting(borderFormatting);
+			return new HSSFBorderFormatting(cfRuleRecord);
+		}
+		else if( create )
+		{
+			borderFormatting = new BorderFormatting();
+			cfRuleRecord.setBorderFormatting(borderFormatting);
+			return new HSSFBorderFormatting(cfRuleRecord);
+		}
+		else
+		{
+			return null;
+		}
 	}
 	/**
 	 * @return - border formatting object  if defined,  <code>null</code> otherwise
 	 */
 	public HSSFBorderFormatting getBorderFormatting()
 	{
-		BorderFormatting bf = cfRuleRecord.getBorderFormatting();
-		if ( bf == null ) {
-			return null;
-		}
-		return new HSSFBorderFormatting(bf);
+		return getBorderFormatting(false);
 	}
 	/**
-	 * @param patternFmt pass <code>null</code> to signify 'pattern unchanged'
+	 * create a new border formatting structure if it does not exist, 
+	 * otherwise just return existing object.
+	 * @return - border formatting object, never returns <code>null</code>. 
 	 */
-	public void setPatternFormatting(HSSFPatternFormatting patternFmt)
+	public HSSFBorderFormatting createBorderFormatting()
 	{
-		PatternFormatting block = patternFmt==null ? null : patternFmt.getPatternFormattingBlock();
-		cfRuleRecord.setPatternFormatting(block);
+		return getBorderFormatting(true);
 	}
+	
+	private HSSFPatternFormatting getPatternFormatting(boolean create)
+	{
+		PatternFormatting patternFormatting = cfRuleRecord.getPatternFormatting();
+		if ( patternFormatting != null) 
+		{
+			cfRuleRecord.setPatternFormatting(patternFormatting);
+			return new HSSFPatternFormatting(cfRuleRecord);
+		}
+		else if( create )
+		{
+			patternFormatting = new PatternFormatting();
+			cfRuleRecord.setPatternFormatting(patternFormatting);
+			return new HSSFPatternFormatting(cfRuleRecord);
+		}
+		else
+		{
+			return null;
+		}
+	}
+	
 	/**
 	 * @return - pattern formatting object  if defined, <code>null</code> otherwise
 	 */
 	public HSSFPatternFormatting getPatternFormatting()
 	{
-		PatternFormatting pf = cfRuleRecord.getPatternFormatting();
-		if ( pf == null ) {
-			return null;
-		}
-		return new HSSFPatternFormatting(pf);
+		return getPatternFormatting(false);
+	}
+	/**
+	 * create a new pattern formatting structure if it does not exist, 
+	 * otherwise just return existing object.
+	 * @return - pattern formatting object, never returns <code>null</code>. 
+	 */
+	public HSSFPatternFormatting createPatternFormatting()
+	{
+		return getPatternFormatting(true);
 	}
 	
 	public String getFormula1()

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java Tue Apr 15 15:47:30 2008
@@ -17,6 +17,7 @@
 
 package org.apache.poi.hssf.usermodel;
 
+import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.cf.FontFormatting;
 /**
  * High level representation for Font Formatting component
@@ -33,28 +34,23 @@
 	public final static short SS_SUPER = FontFormatting.SS_SUPER;
 	/** Escapement type - Subscript */
 	public final static short SS_SUB   = FontFormatting.SS_SUB;
-    
+
 	/** Underline type - None */ 
 	public final static byte U_NONE              = FontFormatting.U_NONE;
-    /** Underline type - Single */ 
+	/** Underline type - Single */ 
 	public final static byte U_SINGLE            = FontFormatting.U_SINGLE;
-    /** Underline type - Double */ 
+	/** Underline type - Double */ 
 	public final static byte U_DOUBLE            = FontFormatting.U_DOUBLE;
 	/**  Underline type - Single Accounting */ 
 	public final static byte U_SINGLE_ACCOUNTING = FontFormatting.U_SINGLE_ACCOUNTING;
-    /** Underline type - Double Accounting */ 
+	/** Underline type - Double Accounting */ 
 	public final static byte U_DOUBLE_ACCOUNTING = FontFormatting.U_DOUBLE_ACCOUNTING;
-    
+
 	private final FontFormatting fontFormatting;
 	
-	public HSSFFontFormatting()
-	{
-		fontFormatting = new FontFormatting();
-	}
-
-	protected HSSFFontFormatting(FontFormatting ff)
+	protected HSSFFontFormatting(CFRuleRecord cfRuleRecord)
 	{
-		fontFormatting = ff;
+		this.fontFormatting = cfRuleRecord.getFontFormatting();
 	}
 	
 	protected FontFormatting getFontFormattingBlock()

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java Tue Apr 15 15:47:30 2008
@@ -20,12 +20,8 @@
 import org.apache.poi.hssf.model.FormulaParser;
 import org.apache.poi.hssf.record.formula.OperationPtg;
 import org.apache.poi.hssf.record.formula.Ptg;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.CreationHelper;
 import org.apache.poi.ss.usermodel.FormulaEvaluator;
-import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.FormulaEvaluator.CellValue;
 
 /**
  * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
@@ -44,7 +40,7 @@
      *  formula evaluated. 
      */
     public static FormulaParser getUnderlyingParser(HSSFWorkbook workbook, String formula) {
-        return new FormulaParser(formula, workbook.getWorkbook());
+        return new FormulaParser(formula, workbook);
     }
     
 
@@ -57,7 +53,7 @@
      */
     void inspectPtgs(String formula) {
     	HSSFWorkbook hssfWb = (HSSFWorkbook)workbook;
-        FormulaParser fp = new FormulaParser(formula, hssfWb.getWorkbook());
+        FormulaParser fp = new FormulaParser(formula, hssfWb);
         fp.parse();
         Ptg[] ptgs = fp.getRPNPtg();
         System.out.println("<ptg-group>");

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFName.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFName.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFName.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFName.java Tue Apr 15 15:47:30 2008
@@ -29,7 +29,7 @@
  */
 
 public class HSSFName implements Name {
-    private Workbook         book;
+    private HSSFWorkbook         book;
     private NameRecord       name;
     
     /** Creates new HSSFName   - called by HSSFWorkbook to create a sheet from
@@ -40,7 +40,7 @@
      * @param book lowlevel Workbook object associated with the sheet.
      */
     
-    protected HSSFName(Workbook book, NameRecord name) {
+    protected HSSFName(HSSFWorkbook book, NameRecord name) {
         this.book = book;
         this.name = name;
     }
@@ -53,7 +53,7 @@
         String result ;
         short indexToExternSheet = name.getExternSheetNumber();
         
-        result = book.findSheetNameFromExternSheet(indexToExternSheet);
+        result = book.getWorkbook().findSheetNameFromExternSheet(indexToExternSheet);
         
         return result;
     }
@@ -77,11 +77,12 @@
     public void setNameName(String nameName){
         name.setNameText(nameName);
         name.setNameTextLength((byte)nameName.length());
+        Workbook wb = book.getWorkbook();
         
         //Check to ensure no other names have the same case-insensitive name
-        for ( int i = book.getNumNames()-1; i >=0; i-- )
+        for ( int i = wb.getNumNames()-1; i >=0; i-- )
         {
-        	NameRecord rec = book.getNameRecord(i);
+        	NameRecord rec = wb.getNameRecord(i);
         	if (rec != name) {
         		if (rec.getNameText().equalsIgnoreCase(getNameName()))
         			throw new IllegalArgumentException("The workbook already contains this name (case-insensitive)");
@@ -111,7 +112,7 @@
     private void setSheetName(String sheetName){
         int sheetNumber = book.getSheetIndex(sheetName);
 
-        short externSheetNumber = book.checkExternSheet(sheetNumber);
+        short externSheetNumber = book.getExternalSheetIndex(sheetNumber);
         name.setExternSheetNumber(externSheetNumber);
 //        name.setIndexToSheet(externSheetNumber);
 

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPatternFormatting.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPatternFormatting.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPatternFormatting.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPatternFormatting.java Tue Apr 15 15:47:30 2008
@@ -17,6 +17,7 @@
 
 package org.apache.poi.hssf.usermodel;
 
+import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.cf.PatternFormatting;
 
 /**
@@ -66,15 +67,13 @@
 	/**  Least Dots */
 	public final static short LEAST_DOTS 			=  PatternFormatting.LEAST_DOTS;
 
-	private PatternFormatting patternFormatting;
+	private final CFRuleRecord cfRuleRecord;
+	private final PatternFormatting patternFormatting;
 	
-	public HSSFPatternFormatting()
+	protected HSSFPatternFormatting(CFRuleRecord cfRuleRecord)
 	{
-		patternFormatting = new PatternFormatting();
-	}
-	protected HSSFPatternFormatting(PatternFormatting patternFormatting)
-	{
-		this.patternFormatting = patternFormatting;
+		this.cfRuleRecord = cfRuleRecord; 
+		this.patternFormatting = cfRuleRecord.getPatternFormatting();
 	}
 
 	protected PatternFormatting getPatternFormattingBlock()
@@ -116,6 +115,10 @@
 	public void setFillBackgroundColor(short bg)
 	{
 		patternFormatting.setFillBackgroundColor(bg);
+		if( bg != 0)
+		{
+			cfRuleRecord.setPatternBackgroundColorModified(true);
+		}
 	}
 
 	/**
@@ -125,6 +128,10 @@
 	public void setFillForegroundColor(short fg)
 	{
 		patternFormatting.setFillForegroundColor(fg);
+		if( fg != 0)
+		{
+			cfRuleRecord.setPatternColorModified(true);
+		}
 	}
 
 	/**
@@ -134,5 +141,9 @@
 	public void setFillPattern(short fp)
 	{
 		patternFormatting.setFillPattern(fp);
+		if( fp != 0)
+		{
+			cfRuleRecord.setPatternStyleModified(true);
+		}
 	}
 }

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=648444&r1=648443&r2=648444&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 Tue Apr 15 15:47:30 2008
@@ -55,7 +55,7 @@
      * reference to containing low level Workbook
      */
 
-    private Workbook book;
+    private HSSFWorkbook book;
 
     /**
      * reference to containing Sheet
@@ -77,7 +77,7 @@
      */
 
     //protected HSSFRow(Workbook book, Sheet sheet, short rowNum)
-    protected HSSFRow(Workbook book, Sheet sheet, int rowNum)
+    protected HSSFRow(HSSFWorkbook book, Sheet sheet, int rowNum)
     {
         this.rowNum = rowNum;
         this.book = book;
@@ -101,7 +101,7 @@
      * @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int)
      */
 
-    protected HSSFRow(Workbook book, Sheet sheet, RowRecord record)
+    protected HSSFRow(HSSFWorkbook book, Sheet sheet, RowRecord record)
     {
         this.book = book;
         this.sheet = sheet;

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=648444&r1=648443&r2=648444&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 Tue Apr 15 15:47:30 2008
@@ -49,7 +49,6 @@
 import org.apache.poi.hssf.record.VCenterRecord;
 import org.apache.poi.hssf.record.WSBoolRecord;
 import org.apache.poi.hssf.record.WindowTwoRecord;
-import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
 import org.apache.poi.hssf.record.formula.Ptg;
 import org.apache.poi.hssf.record.formula.ReferencePtg;
 import org.apache.poi.hssf.util.HSSFCellRangeAddress;
@@ -210,7 +209,7 @@
      */
     public HSSFRow createRow(int rownum)
     {
-        HSSFRow row = new HSSFRow(book, sheet, rownum);
+        HSSFRow row = new HSSFRow(workbook, sheet, rownum);
 
         addRow(row, true);
         return row;
@@ -225,7 +224,7 @@
 
     private HSSFRow createRowFromRecord(RowRecord row)
     {
-        HSSFRow hrow = new HSSFRow(book, sheet, row);
+        HSSFRow hrow = new HSSFRow(workbook, sheet, row);
 
         addRow(hrow, false);
         return hrow;
@@ -411,7 +410,7 @@
 
        //formula fields ( size and data )
        String str_formula = obj_validation.getFirstFormula();
-       FormulaParser fp = new FormulaParser(str_formula, book);
+       FormulaParser fp = new FormulaParser(str_formula, workbook);
        fp.parse();
        Stack ptg_arr = new Stack();
        Ptg[] ptg  = fp.getRPNPtg();
@@ -435,7 +434,7 @@
        if ( obj_validation.getSecondFormula() != null )
        {
          str_formula = obj_validation.getSecondFormula();
-         fp = new FormulaParser(str_formula, book);
+         fp = new FormulaParser(str_formula, workbook);
          fp.parse();
          ptg_arr = new Stack();
          ptg  = fp.getRPNPtg();
@@ -1281,7 +1280,7 @@
                     // Since it's a formula cell, process the
                     //  formula string, and look to see if
                     //  it contains any references
-                    FormulaParser fp = new FormulaParser(c.getCellFormula(), workbook.getWorkbook());
+                    FormulaParser fp = new FormulaParser(c.getCellFormula(), workbook);
                     fp.parse();
 
                     // Look for references, and update if needed
@@ -1856,137 +1855,7 @@
         return null;
     }
 
-
-     /**
-      * A factory method allowing to create a conditional formatting rule
-      * with a cell comparison operator and
-      * formatting rules such as font format, border format and pattern format
-      *
-      * @param comparisonOperation - a constant value from
-      *         <tt>{@link HSSFConditionalFormattingRule.ComparisonOperator}</tt>: <p>
-      * <ul>
-      *         <li>BETWEEN</li>
-      *         <li>NOT_BETWEEN</li>
-      *         <li>EQUAL</li>
-      *         <li>NOT_EQUAL</li>
-      *         <li>GT</li>
-      *         <li>LT</li>
-      *         <li>GE</li>
-      *         <li>LE</li>
-      * </ul>
-      * </p>
-      * @param formula1 - formula for the valued, compared with the cell
-      * @param formula2 - second formula (only used with
-      * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}) and
-      * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN} operations)
-      * @param fontFmt - font formatting rules (may be <code>null</code>)
-      * @param bordFmt - border formatting rules (may be <code>null</code>)
-      * @param patternFmt - pattern formatting rules (may be <code>null</code>)
-      */
-     public HSSFConditionalFormattingRule createConditionalFormattingRule(
-             byte comparisonOperation,
-             String formula1,
-             String formula2,
-             HSSFFontFormatting fontFmt,
-             HSSFBorderFormatting bordFmt,
-             HSSFPatternFormatting patternFmt) {
-    	 
-        Workbook wb = workbook.getWorkbook();
-        CFRuleRecord rr = CFRuleRecord.create(wb, comparisonOperation, formula1, formula2);
-        return new HSSFConditionalFormattingRule(wb, rr, fontFmt, bordFmt, patternFmt);
-     }
-
-     /**
-      * A factory method allowing to create a conditional formatting rule with a formula
-      * and formatting rules such as font format, border format and pattern format. <br>
-      *
-      * The formatting rules are applied by Excel when the value of the formula not equal to 0.
-      *
-      * @param formula - formula for the valued, compared with the cell
-      * @param fontFmt - font formatting rules (may be <code>null</code>)
-      * @param bordFmt - border formatting rules (may be <code>null</code>)
-      * @param patternFmt - pattern formatting rules (may be <code>null</code>)
-      */
-     public HSSFConditionalFormattingRule createConditionalFormattingRule(
-             String formula,
-             HSSFFontFormatting fontFmt,
-             HSSFBorderFormatting bordFmt,
-             HSSFPatternFormatting patternFmt) {
-         Workbook wb = workbook.getWorkbook();
-         CFRuleRecord rr = CFRuleRecord.create(wb, formula);
-         return new HSSFConditionalFormattingRule(wb, rr, fontFmt, bordFmt, patternFmt);
-     }
-
-     /**
-      * Adds a copy of HSSFConditionalFormatting object to the sheet
-      * <p>This method could be used to copy HSSFConditionalFormatting object
-      * from one sheet to another. For example:
-      * <pre>
-      * HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(index);
-      * newSheet.addConditionalFormatting(cf);
-      * </pre>
-      *
-      * @param cf HSSFConditionalFormatting object
-      * @return index of the new Conditional Formatting object
-      */
-     public int addConditionalFormatting( HSSFConditionalFormatting cf ) {
-         CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate();
-
-         return sheet.addConditionalFormatting(cfraClone);
-     }
-
-     /**
-      * Allows to add a new Conditional Formatting set to the sheet.
-      *
-      * @param regions - list of rectangular regions to apply conditional formatting rules
-      * @param hcfRules - set of up to three conditional formatting rules
-      *
-      * @return index of the newly created Conditional Formatting object
-      */
-
-    public int addConditionalFormatting(Region [] regions, HSSFConditionalFormattingRule [] hcfRules) {
-        if (regions == null) {
-            throw new IllegalArgumentException("regions must not be null");
-        }
-        if (hcfRules == null) {
-            throw new IllegalArgumentException("hcfRules must not be null");
-        }
-
-        CFRuleRecord[] rules = new CFRuleRecord[hcfRules.length];
-        for (int i = 0; i != hcfRules.length; i++) {
-            rules[i] = hcfRules[i].getCfRuleRecord();
-        }
-        CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules);
-        return sheet.addConditionalFormatting(cfra);
-     }
-
-    /**
-     * gets Conditional Formatting object at a particular index
-     * 
-     * @param index
-     *            of the Conditional Formatting object to fetch
-     * @return Conditional Formatting object
-     */
-    public HSSFConditionalFormatting getConditionalFormattingAt(int index) {
-        CFRecordsAggregate cf = sheet.getCFRecordsAggregateAt(index);
-        if (cf == null) {
-            return null;
-        }
-        return new HSSFConditionalFormatting(this,cf);
-    }
-
-    /**
-     * @return number of Conditional Formatting objects of the sheet
-     */
-    public int getNumConditionalFormattings() {
-        return sheet.getNumConditionalFormattings();
-    }
-
-    /**
-     * removes a Conditional Formatting object by index
-     * @param index of a Conditional Formatting object to remove
-     */
-    public void removeConditionalFormatting(int index) {
-        sheet.removeConditionalFormatting(index);
+    public HSSFSheetConditionalFormatting getSheetConditionalFormatting() {
+        return new HSSFSheetConditionalFormatting(workbook, sheet);
     }
 }

Copied: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java (from r648334, poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java)
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java?p2=poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java&p1=poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java&r1=648334&r2=648444&rev=648444&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java Tue Apr 15 15:47:30 2008
@@ -20,7 +20,7 @@
 import org.apache.poi.hssf.model.Sheet;
 import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
-import org.apache.poi.hssf.util.Region;
+import org.apache.poi.ss.util.Region;
 
 /**
  * The 'Conditional Formatting' facet of <tt>HSSFSheet</tt>

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=648444&r1=648443&r2=648444&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 Tue Apr 15 15:47:30 2008
@@ -62,6 +62,7 @@
 import org.apache.poi.hssf.record.formula.MemFuncPtg;
 import org.apache.poi.hssf.record.formula.UnionPtg;
 import org.apache.poi.hssf.util.CellReference;
+import org.apache.poi.hssf.util.SheetReferences;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.ss.usermodel.CreationHelper;
@@ -266,7 +267,7 @@
         }
 
         for (int i = 0 ; i < workbook.getNumNames() ; ++i){
-            HSSFName name = new HSSFName(workbook, workbook.getNameRecord(i));
+            HSSFName name = new HSSFName(this, workbook.getNameRecord(i));
             names.add(name);
         }
     }
@@ -539,6 +540,17 @@
     	}
     	return -1;
     }
+    
+    /**
+     * Returns the external sheet index of the sheet
+     *  with the given internal index, creating one
+     *  if needed.
+     * Used by some of the more obscure formula and 
+     *  named range things.
+     */
+    public short getExternalSheetIndex(int internalSheetIndex) {
+    	return workbook.checkExternSheet(internalSheetIndex);
+    }
 
     /**
      * create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns
@@ -668,6 +680,10 @@
         }
         return retval;
     }
+    
+    public SheetReferences getSheetReferences() {
+    	return workbook.getSheetReferences();
+    }
 
     /**
      * removes sheet at the given index
@@ -811,7 +827,7 @@
 
         if (isNewRecord)
         {
-            HSSFName newName = new HSSFName(workbook, nameRecord);
+            HSSFName newName = new HSSFName(this, nameRecord);
             names.add(newName);
         }
 
@@ -1122,6 +1138,17 @@
 
         return result;
     }
+    
+    /**
+     * TODO - make this less cryptic / move elsewhere
+     * @param refIndex Index to REF entry in EXTERNSHEET record in the Link Table
+     * @param definedNameIndex zero-based to DEFINEDNAME or EXTERNALNAME record
+     * @return the string representation of the defined or external name
+     */
+    public String resolveNameXText(int refIndex, int definedNameIndex) {
+    	return workbook.resolveNameXText(refIndex, definedNameIndex);
+    }
+
 
 	/**
 	 * Sets the printarea for the sheet provided
@@ -1180,7 +1207,7 @@
 		if (name == null) return null;
 		//adding one here because 0 indicates a global named region; doesnt make sense for print areas
 
-		return name.getAreaReference(workbook);
+		return name.getAreaReference(this);
 	}
 
     /**
@@ -1197,7 +1224,7 @@
     public HSSFName createName(){
         NameRecord nameRecord = workbook.createName();
 
-        HSSFName newName = new HSSFName(workbook, nameRecord);
+        HSSFName newName = new HSSFName(this, nameRecord);
 
         names.add(newName);
 

Modified: poi/branches/ooxml/src/scratchpad/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java (original)
+++ poi/branches/ooxml/src/scratchpad/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java Tue Apr 15 15:47:30 2008
@@ -459,6 +459,7 @@
         TextBox box2 = new TextBox();
         TextRun tr2 = box2.getTextRun();
         tr2.setRunType(TextHeaderAtom.BODY_TYPE);
+        tr2.getRichTextRuns()[0].setFontSize(32);
         tr2.setText(
                 "Support for more PowerPoint functionality\r" +
                 "Rendering slides into java.awt.Graphics2D");
@@ -477,6 +478,7 @@
         TextBox box4 = new TextBox();
         TextRun tr4 = box4.getTextRun();
         tr4.setRunType(TextHeaderAtom.BODY_TYPE);
+        tr4.getRichTextRuns()[0].setFontSize(32);
         tr4.setText(
                 "Integration with Apache FOP - Formatting Objects Processor");
         box4.setAnchor(new Rectangle(36, 290, 648, 90));

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/AutoShape.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/AutoShape.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/AutoShape.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/AutoShape.java Tue Apr 15 15:47:30 2008
@@ -20,11 +20,15 @@
 import org.apache.poi.ddf.*;
 
 /**
- * Represents a autoshape in a PowerPoint drawing
+ * Represents an AutoShape.
+ * <p>
+ * AutoShapes are drawing objects with a particular shape that may be customized through smart resizing and adjustments.
+ * See {@link ShapeTypes}
+ * </p>
  *
  *  @author Yegor Kozlov
  */
-public class AutoShape extends SimpleShape {
+public class AutoShape extends TextShape {
 
     protected AutoShape(EscherContainerRecord escherRecord, Shape parent){
         super(escherRecord, parent);
@@ -40,23 +44,62 @@
     }
 
     protected EscherContainerRecord createSpContainer(int shapeType, boolean isChild){
-        EscherContainerRecord spcont = super.createSpContainer(isChild);
+        _escherContainer = super.createSpContainer(isChild);
 
-        EscherSpRecord spRecord = spcont.getChildById(EscherSpRecord.RECORD_ID);
-        short type = (short)((shapeType << 4) | 0x2);
-        spRecord.setOptions(type);
+        setShapeType(shapeType);
 
         //set default properties for an autoshape
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
+        setEscherProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x40000);
+        setEscherProperty(EscherProperties.FILL__FILLCOLOR, 0x8000004);
+        setEscherProperty(EscherProperties.FILL__FILLCOLOR, 0x8000004);
+        setEscherProperty(EscherProperties.FILL__FILLBACKCOLOR, 0x8000000);
+        setEscherProperty(EscherProperties.FILL__NOFILLHITTEST, 0x100010);
+        setEscherProperty(EscherProperties.LINESTYLE__COLOR, 0x8000001);
+        setEscherProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80008);
+        setEscherProperty(EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
 
-        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__FILLCOLOR, 0x8000004));
-        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__FILLBACKCOLOR, 0x8000000));
-        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__NOFILLHITTEST, 0x100010));
-        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__COLOR, 0x8000001));
-        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80008));
-        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.SHADOWSTYLE__COLOR, 0x8000002));
+        return _escherContainer;
+    }
+
+    protected void setDefaultTextProperties(TextRun _txtrun){
+        setVerticalAlignment(TextBox.AnchorMiddle);
+        setHorizontalAlignment(TextBox.AlignCenter);
+        setWordWrap(TextBox.WrapNone);
+    }
 
-        return spcont;
+    /**
+     * Gets adjust value which controls smart resizing of the auto-shape.
+     *
+     * <p>
+     * The adjustment values are given in shape coordinates:
+     * the origin is at the top-left, positive-x is to the right, positive-y is down.
+     * The region from (0,0) to (S,S) maps to the geometry box of the shape (S=21600 is a constant).
+     * </p>
+     *
+     * @param idx the adjust index in the [0, 9] range
+     * @return the adjustment value
+     */
+    public int getAdjustmentValue(int idx){
+        if(idx < 0 || idx > 9) throw new IllegalArgumentException("The index of an adjustment value must be in the [0, 9] range");
+
+        return getEscherProperty((short)(EscherProperties.GEOMETRY__ADJUSTVALUE + idx));
     }
 
+    /**
+     * Sets adjust value which controls smart resizing of the auto-shape.
+     *
+     * <p>
+     * The adjustment values are given in shape coordinates:
+     * the origin is at the top-left, positive-x is to the right, positive-y is down.
+     * The region from (0,0) to (S,S) maps to the geometry box of the shape (S=21600 is a constant).
+     * </p>
+     *
+     * @param idx the adjust index in the [0, 9] range
+     * @param val the adjustment value
+     */
+    public void setAdjustmentValue(int idx, int val){
+        if(idx < 0 || idx > 9) throw new IllegalArgumentException("The index of an adjustment value must be in the [0, 9] range");
+
+        setEscherProperty((short)(EscherProperties.GEOMETRY__ADJUSTVALUE + idx), val);
+    }
 }

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Line.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Line.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Line.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Line.java Tue Apr 15 15:47:30 2008
@@ -106,14 +106,14 @@
     }
 
     protected EscherContainerRecord createSpContainer(boolean isChild){
-        EscherContainerRecord spcont = super.createSpContainer(isChild);
+        _escherContainer = super.createSpContainer(isChild);
 
-        EscherSpRecord spRecord = spcont.getChildById(EscherSpRecord.RECORD_ID);
+        EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
         short type = (ShapeTypes.Line << 4) | 0x2;
         spRecord.setOptions(type);
   
         //set default properties for a line
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
 
         //default line properties
         setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, 4);
@@ -123,7 +123,7 @@
         setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0xA0008);
         setEscherProperty(opt, EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
 
-        return spcont;
+        return _escherContainer;
     }
 
 }

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java Tue Apr 15 15:47:30 2008
@@ -120,20 +120,20 @@
      * @return the create Picture object
      */
     protected EscherContainerRecord createSpContainer(int idx, boolean isChild) {
-        EscherContainerRecord spContainer = super.createSpContainer(isChild);
-        spContainer.setOptions((short)15);
+        _escherContainer = super.createSpContainer(isChild);
+        _escherContainer.setOptions((short)15);
 
-        EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID);
+        EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
         spRecord.setOptions((short)((ShapeTypes.PictureFrame << 4) | 0x2));
 
         //set default properties for a picture
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spContainer, EscherOptRecord.RECORD_ID);
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
         setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 8388736);
 
         //another weird feature of powerpoint: for picture id we must add 0x4000.
         setEscherProperty(opt, (short)(EscherProperties.BLIP__BLIPTODISPLAY + 0x4000), idx);
 
-        return spContainer;
+        return _escherContainer;
     }
 
     /**

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java Tue Apr 15 15:47:30 2008
@@ -49,15 +49,15 @@
      * @return the created <code>EscherContainerRecord</code> which holds shape data
      */
     protected EscherContainerRecord createSpContainer(boolean isChild){
-        EscherContainerRecord spcont = super.createSpContainer(isChild);
+        _escherContainer = super.createSpContainer(isChild);
 
-        EscherSpRecord spRecord = spcont.getChildById(EscherSpRecord.RECORD_ID);
+        EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
         spRecord.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HAVEMASTER);
 
         EscherClientDataRecord cldata = new EscherClientDataRecord();
         cldata.setOptions((short)15);
 
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
 
         //Placeholders can't be grouped
         setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 262144);
@@ -86,7 +86,7 @@
         cldata.setRemainingData(out.toByteArray());
 
         //append placeholder container before EscherTextboxRecord
-        List lst = spcont.getChildRecords();
+        List lst = _escherContainer.getChildRecords();
         for (int i = 0; i < lst.size(); i++) {
               EscherRecord rec = (EscherRecord)lst.get(i);
               if(rec.getRecordId() == EscherTextboxRecord.RECORD_ID){
@@ -94,6 +94,6 @@
               }
         }
 
-        return spcont;
+        return _escherContainer;
     }
 }

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=648444&r1=648443&r2=648444&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 Tue Apr 15 15:47:30 2008
@@ -17,6 +17,10 @@
 package org.apache.poi.hslf.model;
 
 import org.apache.poi.ddf.*;
+import org.apache.poi.util.POILogger;
+import org.apache.poi.util.POILogFactory;
+
+import java.util.List;
 
 /**
  * Create a <code>Shape</code> object depending on its type
@@ -24,27 +28,53 @@
  * @author Yegor Kozlov
  */
 public class ShapeFactory {
+    // For logging
+    protected static POILogger logger = POILogFactory.getLogger(ShapeFactory.class);
 
     /**
      * Create a new shape from the data provided.  
      */
     public static Shape createShape(EscherContainerRecord spContainer, Shape parent){
         if (spContainer.getRecordId() == EscherContainerRecord.SPGR_CONTAINER){
-            return new ShapeGroup(spContainer, parent);
+            return createShapeGroup(spContainer, parent);
+        } else {
+            return createSimpeShape(spContainer, parent);
+
+        }
+    }
+
+    public static ShapeGroup createShapeGroup(EscherContainerRecord spContainer, Shape parent){
+        ShapeGroup group = null;
+        UnknownEscherRecord opt = (UnknownEscherRecord)Shape.getEscherChild((EscherContainerRecord)spContainer.getChild(0), (short)0xF122);
+        if(opt != null){
+            try {
+                EscherPropertyFactory f = new EscherPropertyFactory();
+                List props = f.createProperties( opt.getData(), 0, opt.getInstance() );
+                EscherSimpleProperty p = (EscherSimpleProperty)props.get(0);
+                if(p.getPropertyNumber() == 0x39F && p.getPropertyValue() == 1){
+                    group = new ShapeGroup(spContainer, parent);
+                } else {
+                    group = new ShapeGroup(spContainer, parent);
+                }
+            } catch (Exception e){
+                logger.log(POILogger.WARN, e.getMessage());
+                group = new ShapeGroup(spContainer, parent);
+            }
+        }  else {
+            group = new ShapeGroup(spContainer, parent);
         }
 
+        return group;
+     }
+
+    public static Shape createSimpeShape(EscherContainerRecord spContainer, Shape parent){
         Shape shape;
         EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID);
 
         int type = spRecord.getOptions() >> 4;
         switch (type){
             case ShapeTypes.TextBox:
-            case ShapeTypes.Rectangle:
-                EscherTextboxRecord txtbox = (EscherTextboxRecord)Shape.getEscherChild(spContainer, EscherTextboxRecord.RECORD_ID);
-                if (txtbox == null)
-                    shape = new AutoShape(spContainer, parent);
-                else
-                    shape = new TextBox(spContainer, parent);
+                shape = new TextBox(spContainer, parent);
                 break;
             case ShapeTypes.PictureFrame:
                 shape = new Picture(spContainer, parent);
@@ -53,16 +83,21 @@
                 shape = new Line(spContainer, parent);
                 break;
             case ShapeTypes.NotPrimitive:
-                if ((spRecord.getFlags() & EscherSpRecord.FLAG_GROUP) != 0)
-                     shape = new ShapeGroup(spContainer, parent);
-                else
+                EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(spContainer, EscherOptRecord.RECORD_ID);
+                EscherProperty prop = Shape.getEscherProperty(opt, EscherProperties.GEOMETRY__VERTICES);
+                if(prop != null)
+                    shape = new Freeform(spContainer, parent);
+                else {
+
+                    logger.log(POILogger.WARN, "Creating AutoShape for a NotPrimitive shape");
                     shape = new AutoShape(spContainer, parent);
+                }
                 break;
             default:
                 shape = new AutoShape(spContainer, parent);
                 break;
         }
         return shape;
-    }
 
+    }
 }

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java Tue Apr 15 15:47:30 2008
@@ -19,6 +19,7 @@
 import org.apache.poi.ddf.*;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.POILogger;
+import org.apache.poi.hslf.record.EscherTextboxWrapper;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -154,9 +155,10 @@
         shape.setSheet(sheet);
         shape.afterInsert(sheet);
 
-        if(shape instanceof TextBox) {
-            TextBox tbox = (TextBox)shape;
-            getSheet().getPPDrawing().addTextboxWrapper(tbox._txtbox);
+        if (shape instanceof TextShape) {
+            TextShape tbox = (TextShape) shape;
+            EscherTextboxWrapper txWrapper = tbox.getEscherTextboxWrapper();
+            if(txWrapper != null) getSheet().getPPDrawing().addTextboxWrapper(txWrapper);
         }
     }
 

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java Tue Apr 15 15:47:30 2008
@@ -257,11 +257,12 @@
         shape.setSheet(this);
         shape.afterInsert(this);
 
-        // If it's a TextBox, we need to tell the PPDrawing, as it has to
+        // If it's a TextShape, we need to tell the PPDrawing, as it has to
         //  track TextboxWrappers specially
-        if (shape instanceof TextBox) {
-            TextBox tbox = (TextBox) shape;
-            ppdrawing.addTextboxWrapper(tbox._txtbox);
+        if (shape instanceof TextShape) {
+            TextShape tbox = (TextShape) shape;
+            EscherTextboxWrapper txWrapper = tbox.getEscherTextboxWrapper();
+            if(txWrapper != null) ppdrawing.addTextboxWrapper(txWrapper);
         }
     }
 

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java Tue Apr 15 15:47:30 2008
@@ -48,19 +48,19 @@
      * @return the record container which holds this shape
      */
     protected EscherContainerRecord createSpContainer(boolean isChild) {
-        EscherContainerRecord spContainer = new EscherContainerRecord();
-        spContainer.setRecordId( EscherContainerRecord.SP_CONTAINER );
-        spContainer.setOptions((short)15);
+        _escherContainer = new EscherContainerRecord();
+        _escherContainer.setRecordId( EscherContainerRecord.SP_CONTAINER );
+        _escherContainer.setOptions((short)15);
 
         EscherSpRecord sp = new EscherSpRecord();
         int flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
         if (isChild) flags |= EscherSpRecord.FLAG_CHILD;
         sp.setFlags(flags);
-        spContainer.addChildRecord(sp);
+        _escherContainer.addChildRecord(sp);
 
         EscherOptRecord opt = new EscherOptRecord();
         opt.setRecordId(EscherOptRecord.RECORD_ID);
-        spContainer.addChildRecord(opt);
+        _escherContainer.addChildRecord(opt);
 
         EscherRecord anchor;
         if(isChild) anchor = new EscherChildAnchorRecord();
@@ -75,9 +75,9 @@
             LittleEndian.putInt(header, 4, 8);
             anchor.fillFields(header, 0, null);
         }
-        spContainer.addChildRecord(anchor);
+        _escherContainer.addChildRecord(anchor);
 
-        return spContainer;
+        return _escherContainer;
     }
 
     /**

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Table.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Table.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Table.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Table.java Tue Apr 15 15:47:30 2008
@@ -20,10 +20,10 @@
 import org.apache.poi.ddf.*;
 import org.apache.poi.util.LittleEndian;
 
-import java.util.ArrayList;
+import java.util.*;
 import java.util.List;
-import java.util.Iterator;
 import java.awt.*;
+import java.awt.geom.Rectangle2D;
 
 /**
  * Represents a table in a PowerPoint presentation
@@ -142,6 +142,54 @@
             }
         }
 
+    }
+
+    protected void initTable(){
+        Shape[] sh = getShapes();
+        Arrays.sort(sh, new Comparator(){
+            public int compare( Object o1, Object o2 ) {
+                Rectangle anchor1 = ((Shape)o1).getAnchor();
+                Rectangle anchor2 = ((Shape)o2).getAnchor();
+                int delta = anchor1.y - anchor2.y;
+                if(delta == 0) delta = anchor1.x - anchor2.y;
+                return delta;
+            }
+        });
+        int y0 = -1;
+        int maxrowlen = 0;
+        ArrayList lst = new ArrayList();
+        ArrayList row = null;
+        for (int i = 0; i < sh.length; i++) {
+            if(sh[i] instanceof TextShape){
+                Rectangle anchor = sh[i].getAnchor();
+                if(anchor.y != y0){
+                    y0 = anchor.y;
+                    if(row != null) maxrowlen = Math.max(maxrowlen, row.size());
+                    row = new ArrayList();
+                    lst.add(row);
+                }
+                row.add(sh[i]);
+            }
+        }
+        cells = new TableCell[lst.size()][maxrowlen];
+        for (int i = 0; i < lst.size(); i++) {
+            row = (ArrayList)lst.get(i);
+            for (int j = 0; j < row.size(); j++) {
+                TextShape tx = (TextShape)row.get(j);
+                cells[i][j] = new TableCell(tx.getSpContainer(), getParent());
+                cells[i][j].setSheet(tx.getSheet());
+            }
+        }
+    }
+
+    /**
+     * Assign the <code>SlideShow</code> this shape belongs to
+     *
+     * @param sheet owner of this shape
+     */
+    public void setSheet(Sheet sheet){
+        super.setSheet(sheet);
+        if(cells == null) initTable();
     }
 
     /**

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java Tue Apr 15 15:47:30 2008
@@ -63,15 +63,15 @@
     }
 
     protected EscherContainerRecord createSpContainer(boolean isChild){
-        EscherContainerRecord spContainer = super.createSpContainer(isChild);
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spContainer, EscherOptRecord.RECORD_ID);
+        _escherContainer = super.createSpContainer(isChild);
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
         setEscherProperty(opt, EscherProperties.TEXT__TEXTID, 0);
         setEscherProperty(opt, EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x20000);
         setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150001);
         setEscherProperty(opt, EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x20000);
         setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x40000);
 
-        return spContainer;
+        return _escherContainer;
     }
 
     protected void anchorBorder(int type, Line line){

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java Tue Apr 15 15:47:30 2008
@@ -38,55 +38,7 @@
  *
  * @author Yegor Kozlov
  */
-public class TextBox extends SimpleShape {
-
-    /**
-     * How to anchor the text
-     */
-    public static final int AnchorTop = 0;
-    public static final int AnchorMiddle = 1;
-    public static final int AnchorBottom = 2;
-    public static final int AnchorTopCentered = 3;
-    public static final int AnchorMiddleCentered = 4;
-    public static final int AnchorBottomCentered = 5;
-    public static final int AnchorTopBaseline = 6;
-    public static final int AnchorBottomBaseline = 7;
-    public static final int AnchorTopCenteredBaseline = 8;
-    public static final int AnchorBottomCenteredBaseline = 9;
-
-    /**
-     * How to wrap the text
-     */
-    public static final int WrapSquare = 0;
-    public static final int WrapByPoints = 1;
-    public static final int WrapNone = 2;
-    public static final int WrapTopBottom = 3;
-    public static final int WrapThrough = 4;
-
-    /**
-     * How to align the text
-     */
-    public static final int AlignLeft = 0;
-    public static final int AlignCenter = 1;
-    public static final int AlignRight = 2;
-    public static final int AlignJustify = 3;
-
-    /**
-     * Low-level object which holds actual text and format data
-     */
-    protected TextRun _txtrun;
-
-    /**
-     * Escher container which holds text attributes such as
-     * TextHeaderAtom, TextBytesAtom ot TextCharsAtom, StyleTextPropAtom etc.
-     */
-    protected EscherTextboxWrapper _txtbox;
-    
-    /**
-     * Is the TextBox missing the text records which actually
-     *  store the text?
-     */
-    private boolean _missingTextRecords = false;
+public class TextBox extends TextShape {
 
     /**
      * Create a TextBox object and initialize it from the supplied Record container.
@@ -97,8 +49,6 @@
    protected TextBox(EscherContainerRecord escherRecord, Shape parent){
         super(escherRecord, parent);
 
-        EscherTextboxRecord textbox = (EscherTextboxRecord)Shape.getEscherChild(_escherContainer, EscherTextboxRecord.RECORD_ID);
-        _txtbox = new EscherTextboxWrapper(textbox);
     }
 
     /**
@@ -108,8 +58,7 @@
      * in a table then the parent is Table.
      */
     public TextBox(Shape parent){
-        super(null, parent);
-        _escherContainer = createSpContainer(parent instanceof ShapeGroup);
+        super(parent);
     }
 
     /**
@@ -121,376 +70,31 @@
     }
 
     /**
-     * Create a new textBox and initialize internal structures
+     * Create a new TextBox and initialize its internal structures
      *
      * @return the created <code>EscherContainerRecord</code> which holds shape data
      */
     protected EscherContainerRecord createSpContainer(boolean isChild){
-        EscherContainerRecord spcont = super.createSpContainer(isChild);
-
-        EscherSpRecord spRecord = spcont.getChildById(EscherSpRecord.RECORD_ID);
-        short type = (ShapeTypes.TextBox << 4) | 0x2;
-        spRecord.setOptions(type);
-
-        //set default properties for a textbox
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
-        setEscherProperty(opt, EscherProperties.TEXT__TEXTID, 0);
-
-        setEscherProperty(opt, EscherProperties.FILL__FILLCOLOR, 0x8000004);
-        setEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR, 0x8000000);
-        setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x100000);
-        setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, 0x8000001);
-        setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000);
-        setEscherProperty(opt, EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
+        _escherContainer = super.createSpContainer(isChild);
 
-        //create EscherTextboxWrapper
-        _txtbox = new EscherTextboxWrapper();
+        setShapeType(ShapeTypes.TextBox);
 
-        TextHeaderAtom tha = new TextHeaderAtom();
-        tha.setParentRecord(_txtbox); // TextHeaderAtom is parent aware
-        _txtbox.appendChildRecord(tha);
+        //set default properties for a TextBox
+        setEscherProperty(EscherProperties.FILL__FILLCOLOR, 0x8000004);
+        setEscherProperty(EscherProperties.FILL__FILLBACKCOLOR, 0x8000000);
+        setEscherProperty(EscherProperties.FILL__NOFILLHITTEST, 0x100000);
+        setEscherProperty(EscherProperties.LINESTYLE__COLOR, 0x8000001);
+        setEscherProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000);
+        setEscherProperty(EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
 
-        TextCharsAtom tca = new TextCharsAtom();
-        _txtbox.appendChildRecord(tca);
+        _txtrun = createTextRun();
 
-        StyleTextPropAtom sta = new StyleTextPropAtom(0);
-        _txtbox.appendChildRecord(sta);
-
-        _txtrun = new TextRun(tha,tca,sta);
-        _txtrun.setText("");
-        spcont.addChildRecord(_txtbox.getEscherRecord());
-
-        return spcont;
+        return _escherContainer;
     }
 
-    /**
-     * Returns the text contained in this text frame.
-     *
-     * @return the text string for this textbox.
-     */
-     public String getText(){
-        return _txtrun == null ? null : _txtrun.getText();
+    protected void setDefaultTextProperties(TextRun _txtrun){
+        setVerticalAlignment(TextBox.AnchorTop);
+        setEscherProperty(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x20002);
     }
 
-    /**
-     * Sets the text contained in this text frame.
-     *
-     * @param text the text string used by this object.
-     */
-    public void setText(String text){
-        _txtrun.setText(text);
-    }
-
-    /**
-     * When a textbox is added to  a sheet we need to tell upper-level
-     * <code>PPDrawing</code> about it.
-     *
-     * @param sh the sheet we are adding to
-     */
-    protected void afterInsert(Sheet sh){
-        PPDrawing ppdrawing = sh.getPPDrawing();
-        ppdrawing.addTextboxWrapper(_txtbox);
-        // Ensure the escher layer knows about the added records 
-        try {
-            _txtbox.writeOut(null);
-        } catch (IOException e){
-            throw new HSLFException(e);
-        }
-        if(getAnchor().equals(new java.awt.Rectangle()) && !"".equals(getText())) resizeToFitText();
-    }
-
-    /**
-     * Adjust the size of the TextBox so it encompasses the text inside it.
-     */
-    public void resizeToFitText(){
-        try{
-        FontRenderContext frc = new FontRenderContext(null, true, true);
-        RichTextRun rt = _txtrun.getRichTextRuns()[0];
-        int size = rt.getFontSize();
-        int style = 0;
-        if (rt.isBold()) style |= Font.BOLD;
-        if (rt.isItalic()) style |= Font.ITALIC;
-        String fntname = rt.getFontName();
-        Font font = new Font(fntname, style, size);
-
-        TextLayout layout = new TextLayout(getText(), font, frc);
-        int width = Math.round(layout.getAdvance());
-        int height = Math.round(layout.getAscent());
-
-        Dimension txsize = new Dimension(width, height);
-        java.awt.Rectangle anchor = getAnchor();
-        anchor.setSize(txsize);
-        setAnchor(anchor);
-        } catch (Exception e){
-            e.printStackTrace();
-
-        }
-    }
-
-    /**
-     * Returns the type of vertical alignment for the text.
-     * One of the <code>Anchor*</code> constants defined in this class.
-     *
-     * @return the type of alignment
-     */
-    public int getVerticalAlignment(){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT);
-        int valign;
-        if (prop == null){
-            int type = getTextRun().getRunType();
-            switch (type){
-                case TextHeaderAtom.TITLE_TYPE:
-                case TextHeaderAtom.CENTER_TITLE_TYPE:
-                    valign = TextBox.AnchorMiddle;
-                    break;
-                default:
-                    valign = TextBox.AnchorTop;
-                    break;
-            }
-        } else {
-            valign = prop.getPropertyValue();
-        }
-        return valign;
-    }
-
-    /**
-     * Sets the type of vertical alignment for the text.
-     * One of the <code>Anchor*</code> constants defined in this class.
-     *
-     * @param align - the type of alignment
-     */
-    public void setVerticalAlignment(int align){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        setEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT, align);
-    }
-
-    public void setHorizontalAlignment(int align){
-        _txtrun.getRichTextRuns()[0].setAlignment(align);
-    }
-    public int getHorizontalAlignment(){
-        return _txtrun.getRichTextRuns()[0].getAlignment();
-    }
-
-    /**
-     * Returns the distance (in points) between the bottom of the text frame
-     * and the bottom of the inscribed rectangle of the shape that contains the text.
-     * Default value is 1/20 inch.
-     *
-     * @return the botom margin
-     */
-    public int getMarginBottom(){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTBOTTOM);
-        int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue();
-        return val/EMU_PER_POINT;
-    }
-
-    /**
-     * Sets the botom margin.
-     * @see #getMarginBottom()
-     *
-     * @param margin    the bottom margin
-     */
-    public void setMarginBottom(int margin){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        setEscherProperty(opt, EscherProperties.TEXT__TEXTBOTTOM, margin*EMU_PER_POINT);
-    }
-
-    /**
-     *  Returns the distance (in EMUs) between the left edge of the text frame
-     *  and the left edge of the inscribed rectangle of the shape that contains
-     *  the text.
-     *  Default value is 1/10 inch.
-     *
-     * @return the left margin
-     */
-    public int getMarginLeft(){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTBOTTOM);
-        int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue();
-        return val/EMU_PER_POINT;
-    }
-
-    /**
-     * Sets the left margin.
-     * @see #getMarginLeft()
-     *
-     * @param margin    the left margin
-     */
-    public void setMarginLeft(int margin){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        setEscherProperty(opt, EscherProperties.TEXT__TEXTLEFT, margin*EMU_PER_POINT);
-    }
-
-    /**
-     *  Returns the distance (in EMUs) between the right edge of the
-     *  text frame and the right edge of the inscribed rectangle of the shape
-     *  that contains the text.
-     *  Default value is 1/10 inch.
-     *
-     * @return the right margin
-     */
-    public int getMarginRight(){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTRIGHT);
-        int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue();
-        return val/EMU_PER_POINT;
-    }
-
-    /**
-     * Sets the right margin.
-     * @see #getMarginRight()
-     *
-     * @param margin    the right margin
-     */
-    public void setMarginRight(int margin){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        setEscherProperty(opt, EscherProperties.TEXT__TEXTRIGHT, margin*EMU_PER_POINT);
-    }
-
-     /**
-     *  Returns the distance (in EMUs) between the top of the text frame
-     *  and the top of the inscribed rectangle of the shape that contains the text.
-     *  Default value is 1/20 inch.
-     *
-     * @return the top margin
-     */
-    public int getMarginTop(){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTTOP);
-        int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue();
-        return val/EMU_PER_POINT;
-    }
-
-   /**
-     * Sets the top margin.
-     * @see #getMarginTop()
-     *
-     * @param margin    the top margin
-     */
-    public void setMarginTop(int margin){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        setEscherProperty(opt, EscherProperties.TEXT__TEXTTOP, margin*EMU_PER_POINT);
-    }
-
-
-    /**
-     * Returns the value indicating word wrap.
-     * One of the <code>Wrap*</code> constants defined in this class.
-     *
-     * @return the value indicating word wrap
-     */
-    public int getWordWrap(){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__WRAPTEXT);
-        return prop == null ? WrapSquare : prop.getPropertyValue();
-    }
-
-    /**
-     *  Specifies how the text should be wrapped
-     *
-     * @param wrap  the value indicating how the text should be wrapped
-     */
-    public void setWordWrap(int wrap){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        setEscherProperty(opt, EscherProperties.TEXT__WRAPTEXT, wrap);
-    }
-
-    /**
-     * @return id for the text.
-     */
-    public int getTextId(){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTID);
-        return prop == null ? 0 : prop.getPropertyValue();
-    }
-
-    /**
-     * Sets text ID
-     *
-     * @param id of the text
-     */
-    public void setTextId(int id){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        setEscherProperty(opt, EscherProperties.TEXT__TEXTID, id);
-    }
-
-    /**
-     * The color used to fill this shape.
-     *
-     * @param color the background color
-     */
-    public void setBackgroundColor(Color color){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
-        setEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR, rgb);
-    }
-
-    /**
-      * @return the TextRun object for this text box
-      */
-     public TextRun getTextRun(){
-         return _txtrun;
-     }
-
-     public void setSheet(Sheet sheet){
-        _sheet = sheet;
-
-        // Initialize _txtrun object.
-        // (We can't do it in the constructor because the sheet
-        //  is not assigned then, it's only built once we have
-        //  all the records)
-        if(_txtrun == null) initTextRun();
-        if(_txtrun == null) {
-        	// No text records found, skip
-        	_missingTextRecords = true;
-        	return;
-        } else {
-        	_missingTextRecords = false;
-        }
-        
-        // Supply the sheet to our child RichTextRuns
-        _txtrun.setSheet(sheet);
-        RichTextRun[] rt = _txtrun.getRichTextRuns();
-        for (int i = 0; i < rt.length; i++) {
-            rt[i].supplySlideShow(_sheet.getSlideShow());
-        }
-    }
-
-    private void initTextRun(){
-        OutlineTextRefAtom ota = null;
-        
-        // Find the interesting child records 
-        Record[] child = _txtbox.getChildRecords();
-        for (int i = 0; i < child.length; i++) {
-            if (child[i] instanceof OutlineTextRefAtom) {
-                ota = (OutlineTextRefAtom)child[i];
-                break;
-            }
-        }
-
-        Sheet sheet = getSheet();
-        TextRun[] runs = sheet.getTextRuns();
-        if (ota != null) {
-            int idx = ota.getTextIndex();
-            for (int i = 0; i < runs.length; i++) {
-                if(runs[i].getIndex() == idx){
-                    _txtrun = runs[i];
-                }
-            }
-            if(_txtrun == null) {
-                logger.log(POILogger.WARN, "text run not found for OutlineTextRefAtom.TextIndex=" + idx);
-            }
-        } else {
-            int shapeId = _escherContainer.getChildById(EscherSpRecord.RECORD_ID).getShapeId();
-            if(runs != null) for (int i = 0; i < runs.length; i++) {
-                if(runs[i].getShapeId() == shapeId){
-                    _txtrun = runs[i];
-                    break;
-                }
-            }
-        }
-
-    }
 }

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=648444&r1=648443&r2=648444&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 Tue Apr 15 15:47:30 2008
@@ -24,12 +24,7 @@
 import java.util.Vector;
 
 import org.apache.poi.hslf.model.textproperties.TextPropCollection;
-import org.apache.poi.hslf.record.Record;
-import org.apache.poi.hslf.record.RecordContainer;
-import org.apache.poi.hslf.record.StyleTextPropAtom;
-import org.apache.poi.hslf.record.TextBytesAtom;
-import org.apache.poi.hslf.record.TextCharsAtom;
-import org.apache.poi.hslf.record.TextHeaderAtom;
+import org.apache.poi.hslf.record.*;
 import org.apache.poi.hslf.usermodel.RichTextRun;
 import org.apache.poi.hslf.usermodel.SlideShow;
 import org.apache.poi.util.StringUtil;
@@ -50,6 +45,7 @@
 	protected TextBytesAtom  _byteAtom;
 	protected TextCharsAtom  _charAtom;
 	protected StyleTextPropAtom _styleAtom;
+    protected TextSpecInfoAtom  _specAtom;
 	protected boolean _isUnicode;
 	protected RichTextRun[] _rtRuns;
 	private SlideShow slideShow;
@@ -477,6 +473,18 @@
 			// Recreate rich text run with no styling
 			_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());
+            }
+
+        }
 	}
 
 	/**

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java Tue Apr 15 15:47:30 2008
@@ -75,16 +75,20 @@
      * @return zero based index of the font in the collection
      */
     public int addFont(String name) {
-        for (int i = 0; i < fonts.size(); i++) {
-            if(fonts.get(i).equals(name)){
-                //if the font is already present return its index
-                return i;
-            }
-        }
+        int idx = getFontIndex(name);
+        if(idx != -1) return idx;
+
+        return addFont(name, 0, 0, 4, 34);
+    }
 
+    public int addFont(String name, int charset, int flags, int type, int pitch) {
         FontEntityAtom fnt = new FontEntityAtom();
         fnt.setFontIndex(fonts.size() << 4);
         fnt.setFontName(name);
+        fnt.setCharSet(charset);
+        fnt.setFontFlags(flags);
+        fnt.setFontType(type);
+        fnt.setPitchAndFamily(pitch);
         fonts.add(name);
 
         // Append new child to the end
@@ -92,8 +96,25 @@
 
         return fonts.size()-1; //the added font is the last in the list
     }
-    
-	/**
+
+    /**
+     * @return zero based index of the font in the collection or -1 if not found
+     */
+    public int getFontIndex(String name) {
+        for (int i = 0; i < fonts.size(); i++) {
+            if(fonts.get(i).equals(name)){
+                //if the font is already present return its index
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    public int getNumberOfFonts() {
+        return fonts.size();
+    }
+
+    /**
 	 * Get the name of the font at the given ID, or null if there is
 	 *  no font at that ID.
 	 * @param id

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java?rev=648444&r1=648443&r2=648444&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java Tue Apr 15 15:47:30 2008
@@ -61,7 +61,7 @@
     /**
      * Create a new instance of <code>FontEntityAtom</code>
      */
-    protected FontEntityAtom() {
+    public FontEntityAtom() {
         _recdata = new byte[68];
 
         _header = new byte[8];
@@ -124,15 +124,100 @@
         }
     }
 
-    protected void setFontIndex(int idx){
+    public void setFontIndex(int idx){
         LittleEndian.putShort(_header, 0, (short)idx);
     }
 
-    protected int getFontIndex(){
-        return LittleEndian.getShort(_header, 0);
+    public int getFontIndex(){
+        return LittleEndian.getShort(_header, 0) >> 4;
     }
 
-	/**
+    /**
+     * set the character set
+     *
+     * @param charset - characterset
+     */
+    public void setCharSet(int charset){
+        _recdata[64] = (byte)charset;
+    }
+
+    /**
+     * get the character set
+     *
+     * @return charset - characterset
+     */
+    public int getCharSet(){
+        return _recdata[64];
+    }
+
+    /**
+     * set the font flags
+     * Bit 1: If set, font is subsetted
+     *
+     * @param flags - the font flags
+     */
+    public void setFontFlags(int flags){
+        _recdata[65] = (byte)flags;
+    }
+
+    /**
+     * get the character set
+     * Bit 1: If set, font is subsetted
+     *
+     * @return the font flags
+     */
+    public int getFontFlags(){
+        return _recdata[65];
+    }
+
+    /**
+     * set the font type
+     * <p>
+     * Bit 1: Raster Font
+     * Bit 2: Device Font
+     * Bit 3: TrueType Font
+     * </p>
+     *
+     * @param type - the font type
+     */
+    public void setFontType(int type){
+        _recdata[66] = (byte)type;
+    }
+
+    /**
+     * get the font type
+     * <p>
+     * Bit 1: Raster Font
+     * Bit 2: Device Font
+     * Bit 3: TrueType Font
+     * </p>
+     *
+     * @return the font type
+     */
+    public int getFontType(){
+        return _recdata[66];
+    }
+
+    /**
+     * set lfPitchAndFamily
+     *
+     *
+     * @param val - Corresponds to the lfPitchAndFamily field of the Win32 API LOGFONT structure
+     */
+    public void setPitchAndFamily(int val){
+        _recdata[67] = (byte)val;
+    }
+
+    /**
+     * get lfPitchAndFamily
+     *
+     * @return corresponds to the lfPitchAndFamily field of the Win32 API LOGFONT structure
+     */
+    public int getPitchAndFamily(){
+        return _recdata[67];
+    }
+
+    /**
 	 * Write the contents of the record back, so it can be written to disk
 	 */
 	public void writeOut(OutputStream out) throws IOException {

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=648444&r1=648443&r2=648444&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 Tue Apr 15 15:47:30 2008
@@ -92,7 +92,7 @@
     public static final Type TextBookmarkAtom = new Type(4007,null);
     public static final Type TextBytesAtom = new Type(4008,TextBytesAtom.class);
     public static final Type TxSIStyleAtom = new Type(4009,null);
-    public static final Type TextSpecInfoAtom = new Type(4010,null);
+    public static final Type TextSpecInfoAtom = new Type(4010, TextSpecInfoAtom.class);
     public static final Type DefaultRulerAtom = new Type(4011,null);
     public static final Type FontEntityAtom = new Type(4023,FontEntityAtom.class);
     public static final Type FontEmbeddedData = new Type(4024,null);



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