[Libreoffice-commits] core.git: Branch 'feature/table-style' - sw/inc sw/source

Alex Ivan alexnivan at yahoo.com
Mon Jul 8 10:57:03 PDT 2013


 sw/inc/swtblfmt.hxx              |    9 ++++++
 sw/inc/tblafmt.hxx               |    2 -
 sw/source/core/doc/swtblfmt.cxx  |   34 ++++++++++++++++++++--
 sw/source/core/docnode/ndtbl.cxx |   58 +++++++++++++++++++++++++++------------
 4 files changed, 81 insertions(+), 22 deletions(-)

New commits:
commit b60730b1768f19cdddf738d23712786853e839c6
Author: Alex Ivan <alexnivan at yahoo.com>
Date:   Mon Jul 8 20:54:39 2013 +0300

    Use SwTableFmt in InsertTable method
    
    Partially replaced the role of SwTableAutoFormat in
    insertTable method with SwTableFmt.
    
    Change-Id: Icfe402d711bda17acd1aa8c2a5ac819a438c7d74

diff --git a/sw/inc/swtblfmt.hxx b/sw/inc/swtblfmt.hxx
index d49396a..03c3974 100644
--- a/sw/inc/swtblfmt.hxx
+++ b/sw/inc/swtblfmt.hxx
@@ -40,9 +40,12 @@
 #include <editeng/formatbreakitem.hxx>
 #include <editeng/keepitem.hxx>
 #include <editeng/lineitem.hxx>
+#include <editeng/lrspitem.hxx>
 #include <editeng/frmdiritem.hxx>
 #include <editeng/shaditem.hxx>
 #include <editsh.hxx>
+#include <fmtfordr.hxx>
+#include <fmtfsize.hxx>
 #include <fmtpdsc.hxx>
 #include <fmtlsplt.hxx>
 #include <fmtornt.hxx>
@@ -114,6 +117,10 @@ public:
     void SetRowSplit( const sal_Bool& rNew );
     void SetRepeatHeading( const sal_uInt16& rNew );
     void SetShadow( const SvxShadowItem& rNew );
+    void SetFrameDir( const SvxFrameDirectionItem& rNew );
+    void SetHoriOrient( const SwFmtHoriOrient& rNew );
+    void SetLRSpace( const SvxLRSpaceItem& rNew );
+    void SetFmtFrmSize( const SwFmtFrmSize& rNew );
 
     const SvxFmtKeepItem& GetKeepWithNextPara() const;
     sal_Bool GetLayoutSplit() const;
@@ -164,6 +171,8 @@ public:
     SwTableBoxFmt* GetOddBoxFmt() { return m_pOddBoxFmt.get(); }
     SwTableBoxFmt* GetEvenBoxFmt() { return m_pEvnBoxFmt.get(); }
 
+    void SetFillOrder( const SwFmtFillOrder& rNew );
+
     TYPEINFO();     // Already in base class Content.
 
     DECL_FIXEDMEMPOOL_NEWDEL(SwTableLineFmt)
diff --git a/sw/inc/tblafmt.hxx b/sw/inc/tblafmt.hxx
index a1e59b3..b095765 100644
--- a/sw/inc/tblafmt.hxx
+++ b/sw/inc/tblafmt.hxx
@@ -128,7 +128,7 @@ public:
 
     SwTableAutoFmt& operator=( const SwTableAutoFmt& rNew );
 
-    SwTableFmt* GetTableStyle() { return m_pTableStyle; }
+    SwTableFmt* GetTableStyle() const { return m_pTableStyle; }
 
     void SetBoxFmt( const SwTableBoxFmt& rNew, sal_uInt8 nPos );
     SwTableBoxFmt* GetBoxFmt( sal_uInt8 nPos ) const;
diff --git a/sw/source/core/doc/swtblfmt.cxx b/sw/source/core/doc/swtblfmt.cxx
index 5e348e7..393218c 100644
--- a/sw/source/core/doc/swtblfmt.cxx
+++ b/sw/source/core/doc/swtblfmt.cxx
@@ -117,9 +117,9 @@ void SwTableFmt::SetBoxFmt( const SwTableBoxFmt& rNew, sal_uInt8 nPos )
         case 0:
             pLine = m_pFstLineFmt.get(); break;
         case 1:
-            pLine = m_pOddLineFmt.get(); break;
-        case 2:
             pLine = m_pEvnLineFmt.get(); break;
+        case 2:
+            pLine = m_pOddLineFmt.get(); break;
         case 3:
             pLine = m_pLstLineFmt.get(); break;
         // TODO Extend for columns
@@ -130,9 +130,9 @@ void SwTableFmt::SetBoxFmt( const SwTableBoxFmt& rNew, sal_uInt8 nPos )
         case 0:
             pLine->SetFirstBoxFmt( new SwTableBoxFmt( rNew ) ); break;
         case 1:
-            pLine->SetOddBoxFmt( new SwTableBoxFmt( rNew ) ); break;
-        case 2:
             pLine->SetEvenBoxFmt( new SwTableBoxFmt( rNew ) ); break;
+        case 2:
+            pLine->SetOddBoxFmt( new SwTableBoxFmt( rNew ) ); break;
         case 3:
             pLine->SetLastBoxFmt( new SwTableBoxFmt( rNew ) ); break;
     }
@@ -216,6 +216,27 @@ void SwTableFmt::SetShadow( const SvxShadowItem& rNew )
     SetFmtAttr( rNew );
 }
 
+void SwTableFmt::SetFrameDir( const SvxFrameDirectionItem& rNew )
+{
+    SetFmtAttr( rNew );
+}
+
+
+void SwTableFmt::SetHoriOrient( const SwFmtHoriOrient& rNew )
+{
+    SetFmtAttr( rNew );
+}
+
+void SwTableFmt::SetLRSpace( const SvxLRSpaceItem& rNew )
+{
+    SetFmtAttr( rNew );
+}
+
+void SwTableFmt::SetFmtFrmSize( const SwFmtFrmSize& rNew )
+{
+    SetFmtAttr( rNew );
+}
+
 const SvxFmtKeepItem& SwTableFmt::GetKeepWithNextPara() const
 {
     return SwFmt::GetKeep();
@@ -342,6 +363,11 @@ SwTableLineFmt& SwTableLineFmt::operator=( const SwTableLineFmt& rNew )
         return *this;
     }
 
+void SwTableLineFmt::SetFillOrder( const SwFmtFillOrder& rNew )
+{
+    SetFmtAttr( rNew );
+}
+
 SwTableBoxFmt::SwTableBoxFmt( SwAttrPool& rPool, const sal_Char* pFmtNm,
                     SwFrmFmt *pDrvdFrm )
     : SwFrmFmt( rPool, pFmtNm, pDrvdFrm, RES_FRMFMT, aTableBoxSetRange )
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index f8b224f..1f556c3 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -389,8 +389,11 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTblOpts,
         bCalledFromShell ? &pCntntNd->GetSwAttrSet() : 0 );
 
     // Create the Box/Line/Table construct
-    SwTableLineFmt* pLineFmt = MakeTableLineFmt();
-    SwTableFmt* pTableFmt = MakeTblFrmFmt( aTblName, GetDfltFrmFmt() );
+    SwTableFmt* pTableFmt;
+    if( pTAFmt )
+        pTableFmt = pTAFmt->GetTableStyle();
+    else
+        pTableFmt = MakeTblFrmFmt( aTblName, GetDfltFrmFmt() );
 
     /* If the node to insert the table at is a context node and has a
        non-default FRAMEDIR propagate it to the table. */
@@ -402,14 +405,17 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTblOpts,
         if (SFX_ITEM_SET == aNdSet.GetItemState( RES_FRAMEDIR, sal_True, &pItem )
             && pItem != NULL)
         {
-            pTableFmt->SetFmtAttr( *pItem );
+            pTableFmt->SetFrameDir( *static_cast<const SvxFrameDirectionItem *>( pItem ) );
         }
     }
 
     // Set Orientation at the Table's Fmt
-    pTableFmt->SetFmtAttr( SwFmtHoriOrient( 0, eAdjust ) );
+    pTableFmt->SetHoriOrient( SwFmtHoriOrient( 0, eAdjust ) );
     // All lines use the left-to-right Fill-Order!
-    pLineFmt->SetFmtAttr( SwFmtFillOrder( ATT_LEFT_TO_RIGHT ));
+    pTableFmt->GetFirstLineFmt()->SetFillOrder( SwFmtFillOrder( ATT_LEFT_TO_RIGHT ) );
+    pTableFmt->GetLastLineFmt()->SetFillOrder( SwFmtFillOrder( ATT_LEFT_TO_RIGHT ) );
+    pTableFmt->GetOddLineFmt()->SetFillOrder( SwFmtFillOrder( ATT_LEFT_TO_RIGHT ) );
+    pTableFmt->GetEvenLineFmt()->SetFillOrder( SwFmtFillOrder( ATT_LEFT_TO_RIGHT ) );
 
     // Set USHRT_MAX as the Table's default SSize
     SwTwips nWidth = USHRT_MAX;
@@ -421,7 +427,7 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTblOpts,
         {
             sal_uInt16 nFrmWidth = nLastPos;
             nLastPos = (*pColArr)[ pColArr->size()-2 ];
-            pTableFmt->SetFmtAttr( SvxLRSpaceItem( nSttPos, nFrmWidth - nLastPos, 0, 0, RES_LR_SPACE ) );
+            pTableFmt->SetLRSpace( SvxLRSpaceItem( nSttPos, nFrmWidth - nLastPos, 0, 0, RES_LR_SPACE ) );
         }
         nWidth = nLastPos - nSttPos;
     }
@@ -430,9 +436,9 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTblOpts,
         nWidth /= nCols;
         nWidth *= nCols; // to avoid rounding problems
     }
-    pTableFmt->SetFmtAttr( SwFmtFrmSize( ATT_VAR_SIZE, nWidth ));
+    pTableFmt->SetFmtFrmSize( SwFmtFrmSize( ATT_VAR_SIZE, nWidth ));
     if( !(rInsTblOpts.mnInsMode & tabopts::SPLIT_LAYOUT) )
-        pTableFmt->SetFmtAttr( SwFmtLayoutSplit( sal_False ));
+        pTableFmt->SetLayoutSplit( sal_False );
 
     // Move the hard PageDesc/PageBreak Attributes if needed
     SwCntntNode* pNextNd = GetNodes()[ pTblNd->EndOfSectionIndex()+1 ]
@@ -444,14 +450,14 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTblOpts,
         if( SFX_ITEM_SET == pNdSet->GetItemState( RES_PAGEDESC, sal_False,
             &pItem ) )
         {
-            pTableFmt->SetFmtAttr( *pItem );
+            pTableFmt->SetPageDesc( *static_cast<const SwFmtPageDesc *>( pItem ) );
             pNextNd->ResetAttr( RES_PAGEDESC );
             pNdSet = pNextNd->GetpSwAttrSet();
         }
         if( pNdSet && SFX_ITEM_SET == pNdSet->GetItemState( RES_BREAK, sal_False,
              &pItem ) )
         {
-            pTableFmt->SetFmtAttr( *pItem );
+            pTableFmt->SetBreak( *static_cast<const SvxFmtBreakItem *>( pItem ) );
             pNextNd->ResetAttr( RES_BREAK );
         }
     }
@@ -471,8 +477,7 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTblOpts,
     }
     else
     {
-        const sal_uInt16 nBoxArrLen = pTAFmt ? 16 : 4;
-        aBoxFmtArr.resize( nBoxArrLen, NULL );
+        aBoxFmtArr.resize( 4, NULL );
     }
     SfxItemSet aCharSet( GetAttrPool(), RES_CHRATR_BEGIN, RES_PARATR_LIST_END-1 );
 
@@ -480,7 +485,29 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTblOpts,
     SwTableLines& rLines = pNdTbl->GetTabLines();
     for( sal_uInt16 n = 0; n < nRows; ++n )
     {
-        SwTableLine* pLine = new SwTableLine( pLineFmt, nCols, 0 );
+        SwTableLine* pLine;
+        sal_uInt8 nId;
+        if( !n )
+        {
+            pLine = new SwTableLine( pTableFmt->GetFirstLineFmt(), nCols, 0 );
+            nId = 0;
+        }
+        else if( n == nRows - 1 )
+        {
+            pLine = new SwTableLine( pTableFmt->GetLastLineFmt(), nCols, 0 );
+            nId = 12;
+        }
+        else if( n % 2 )    // considering the user starts counting at 1, not 0
+        {
+            pLine = new SwTableLine( pTableFmt->GetEvenLineFmt(), nCols, 0 );
+            nId = 4;
+        }
+        else
+        {
+            pLine = new SwTableLine( pTableFmt->GetOddLineFmt(), nCols, 0 );
+            nId = 8;
+        }
+
         rLines.insert( rLines.begin() + n, pLine );
         SwTableBoxes& rBoxes = pLine->GetTabBoxes();
         for( sal_uInt16 i = 0; i < nCols; ++i )
@@ -488,12 +515,9 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTblOpts,
             SwTableBoxFmt *pBoxF;
             if( pTAFmt )
             {
-                sal_uInt8 nId = static_cast<sal_uInt8>(!n ? 0 : (( n+1 == nRows )
-                                        ? 12 : (4 * (1 + ((n-1) & 1 )))));
                 nId = nId + static_cast<sal_uInt8>( !i ? 0 :
                             ( i+1 == nCols ? 3 : (1 + ((i-1) & 1))));
-                pBoxF = ::lcl_CreateAFmtBoxFmt( *this, aBoxFmtArr, *pTAFmt,
-                                                nCols, nId );
+                pBoxF = pTableFmt->GetBoxFmt( nId );
 
                 // Set the Paragraph/Character Attributes if needed
                 if( pTAFmt->IsFont() || pTAFmt->IsJustify() )


More information about the Libreoffice-commits mailing list