Hello Here is some new patchs on the format clipboard. The first just add some comment in the formatclipboard.hxx file. The second one depend on modifications I made in the previous patch 0001-add-GetCurParAttr-and-GetPaMParAttr-in-SwEditShell.patch which is itself dependant of the patch 0004-SwEditShell-use-of-the-STL-swap-function.patch which is waiting for moderator approval to be published in the mailing list. This second patch modify the format paintbrush feature, here is a copy of the commit description : With this patch the format paintbrush differentiate automatic character attributes apply to character than those apply to paragraph. Character attributes applied to paragraph are treat as paragraph format when paragraph format are copied (and so apply to paragraph), and treat as character format when paragraph format are not copied. It also change the behavior of the format paintbrush on "restart numbering" and "restart numbering at" attributes. With this patch those attributes are simply copied… as expected. Regards Maxime de Roucy -- Maxime de Roucy Groupe LINAGORA - OSSA 80 rue Roque de Fillol 92800 PUTEAUX Tel. : 0 810 251 251
From 90a80f234f60bd4d5b48cf725f25771fb92975b6 Mon Sep 17 00:00:00 2001 From: Maxime de Roucy <mderoucy@linagora.com> Date: Wed, 14 Mar 2012 15:39:31 +0100 Subject: [PATCH 1/2] Add comments in formatclipboard.hxx --- sw/source/ui/inc/formatclipboard.hxx | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/sw/source/ui/inc/formatclipboard.hxx b/sw/source/ui/inc/formatclipboard.hxx index 07891a0..49f47dc 100644 --- a/sw/source/ui/inc/formatclipboard.hxx +++ b/sw/source/ui/inc/formatclipboard.hxx @@ -46,24 +46,54 @@ public: SwFormatClipboard(); ~SwFormatClipboard(); + /** + * Test if the object contain text or paragraphe attribut + */ bool HasContent() const; bool HasContentForThisType( int nSelectionType ) const; bool CanCopyThisType( int nSelectionType ) const; + /** + * Store/Backup the text and paragraph attribut of the current selection. + * + * @param bPersistentCopy + * input parameter - specify if the Paste function will erase the current object. + */ void Copy( SwWrtShell& rWrtShell, SfxItemPool& rPool, bool bPersistentCopy=false ); + + /** + * Paste the stored text and paragraph attributs on the current selection and current paragraph. + * + * @param bNoCharacterFormats + * Do not past the charactere formats. + * + * @param bNoParagraphFormats + * Do not past the paragraph formats. + */ void Paste( SwWrtShell& rWrtShell, SfxStyleSheetBasePool* pPool , bool bNoCharacterFormats=false, bool bNoParagraphFormats=false ); + + /** + * Clear the current text and paragraph attributs stored. + */ void Erase(); private: int m_nSelectionType; + + /** automatic/named character and paragraph attribut set */ SfxItemSet* m_pItemSet; + + /** table attribut set */ SfxItemSet* m_pTableItemSet; + /** name of the character format (if it exist) */ String m_aCharStyle; + /** name of the paragraph format (if it exist) */ String m_aParaStyle; //no frame style because it contains position information + /** specify if the Paste function have to clear the current object */ bool m_bPersistentCopy; }; -- 1.7.9.4
From 0af328d505bbe16bca32ec27b05e8666eaa6075c Mon Sep 17 00:00:00 2001 From: Maxime de Roucy <mderoucy@linagora.com> Date: Wed, 14 Mar 2012 16:07:57 +0100 Subject: [PATCH 2/2] Rewrite of the format paintbrush MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With this patch the format paintbrush differentiate automatic character attributes apply to character than those apply to paragraph. Character attributes applied to paragraph are treat as paragraph format when paragraph format are copied (and so apply to paragraph), and treat as character format when paragraph format are not copied. It also change the behavior of the format paintbrush on "restart numbering" and "restart numbering at" attributes. With this patch those attributes are simply copied… as expected. --- sw/source/ui/inc/formatclipboard.hxx | 7 +- sw/source/ui/uiview/formatclipboard.cxx | 270 ++++++++++++++++++------------- 2 files changed, 165 insertions(+), 112 deletions(-) diff --git a/sw/source/ui/inc/formatclipboard.hxx b/sw/source/ui/inc/formatclipboard.hxx index 49f47dc..e227622 100644 --- a/sw/source/ui/inc/formatclipboard.hxx +++ b/sw/source/ui/inc/formatclipboard.hxx @@ -81,8 +81,11 @@ public: private: int m_nSelectionType; - /** automatic/named character and paragraph attribut set */ - SfxItemSet* m_pItemSet; + /** automatic/named character attribut set */ + SfxItemSet* m_pItemSet_TxtAttr; + /** automatic/named paragraph attribut set + * (it can be caractere attribut applyied to paragraphe) */ + SfxItemSet* m_pItemSet_ParAttr; /** table attribut set */ SfxItemSet* m_pTableItemSet; diff --git a/sw/source/ui/uiview/formatclipboard.cxx b/sw/source/ui/uiview/formatclipboard.cxx index 61dfd31..57b1844 100644 --- a/sw/source/ui/uiview/formatclipboard.cxx +++ b/sw/source/ui/uiview/formatclipboard.cxx @@ -84,12 +84,9 @@ RES_TEXTGRID, RES_FRMATR_END-1, #define FORMAT_PAINTBRUSH_PARAGRAPH_IDS \ RES_PARATR_BEGIN, RES_PARATR_END -1, \ RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END -1, \ -FORMAT_PAINTBRUSH_FRAME_IDS \ -FN_NUMBER_NEWSTART, FN_NUMBER_NEWSTART, \ -FN_NUMBER_NEWSTART_AT, FN_NUMBER_NEWSTART_AT, +FORMAT_PAINTBRUSH_FRAME_IDS -SfxItemSet* lcl_CreateEmptyItemSet( int nSelectionType, SfxItemPool& rPool - , bool bNoCharacterFormats = false, bool bNoParagraphFormats = false ) +SfxItemSet* lcl_CreateEmptyItemSet( int nSelectionType, SfxItemPool& rPool, bool bNoParagraphFormats = false ) { SfxItemSet* pItemSet = 0; if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) ) @@ -102,30 +99,9 @@ SfxItemSet* lcl_CreateEmptyItemSet( int nSelectionType, SfxItemPool& rPool { //is handled different } - else if( nSelectionType == nsSelectionType::SEL_TBL ) - { - pItemSet = new SfxItemSet(rPool, - SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_SHADOW, //SID_ATTR_BORDER_OUTER is inbetween - RES_BACKGROUND, RES_SHADOW, //RES_BOX is inbetween - SID_ATTR_BRUSH_ROW, SID_ATTR_BRUSH_TABLE, - RES_BREAK, RES_BREAK, - RES_PAGEDESC, RES_PAGEDESC, - RES_LAYOUT_SPLIT, RES_LAYOUT_SPLIT, - RES_ROW_SPLIT, RES_ROW_SPLIT, - RES_KEEP, RES_KEEP, - RES_FRAMEDIR, RES_FRAMEDIR, - FN_PARAM_TABLE_HEADLINE, FN_PARAM_TABLE_HEADLINE, - FN_TABLE_BOX_TEXTORIENTATION, FN_TABLE_BOX_TEXTORIENTATION, - FN_TABLE_SET_VERT_ALIGN, FN_TABLE_SET_VERT_ALIGN, - 0); - } else if( nSelectionType & nsSelectionType::SEL_TXT ) { - if( bNoCharacterFormats ) - pItemSet = new SfxItemSet(rPool, - FORMAT_PAINTBRUSH_PARAGRAPH_IDS - 0); - else if( bNoParagraphFormats ) + if( bNoParagraphFormats ) pItemSet = new SfxItemSet(rPool, RES_CHRATR_BEGIN, RES_CHRATR_END - 1, 0); @@ -270,20 +246,23 @@ void lcl_setTableAttributes( const SfxItemSet& rSet, SwWrtShell &rSh ) SwFormatClipboard::SwFormatClipboard() : m_nSelectionType(0) - , m_pItemSet(0) + , m_pItemSet_TxtAttr(0) + , m_pItemSet_ParAttr(0) , m_pTableItemSet(0) , m_bPersistentCopy(false) { } SwFormatClipboard::~SwFormatClipboard() { - delete m_pItemSet; + delete m_pItemSet_TxtAttr; + delete m_pItemSet_ParAttr; delete m_pTableItemSet; } bool SwFormatClipboard::HasContent() const { - return m_pItemSet!=0 + return m_pItemSet_TxtAttr!=0 + || m_pItemSet_ParAttr!=0 || m_pTableItemSet != 0 || m_aCharStyle.Len() || m_aParaStyle.Len() @@ -319,61 +298,88 @@ bool SwFormatClipboard::CanCopyThisType( int nSelectionType ) const void SwFormatClipboard::Copy( SwWrtShell& rWrtShell, SfxItemPool& rPool, bool bPersistentCopy ) { + // first clear the previously stored attributs this->Erase(); m_bPersistentCopy = bPersistentCopy; int nSelectionType = rWrtShell.GetSelectionType(); - SfxItemSet* pItemSet = lcl_CreateEmptyItemSet( nSelectionType, rPool ); + SfxItemSet* pItemSet_TxtAttr = lcl_CreateEmptyItemSet( nSelectionType, rPool, true ); + SfxItemSet* pItemSet_ParAttr = lcl_CreateEmptyItemSet( nSelectionType, rPool, false ); rWrtShell.StartAction(); rWrtShell.Push(); + + // modify the "Point and Mark" of the cursor + // in order to select only the last charactere of the + // selection(s) and then to get the attributes of this single character if( nSelectionType == nsSelectionType::SEL_TXT ) { + // get the current PaM, the cursor + // if there several selection it curently point + // on the last (sort by there creation time) selection SwPaM* pCrsr = rWrtShell.GetCrsr(); - //select one character only to get the attributes of this single character only + sal_Bool bHasSelection = pCrsr->HasMark(); sal_Bool bForwardSelection = sal_False; - if(!bHasSelection) //check for and handle multiselections + if(!bHasSelection && pCrsr->GetPrev() != pCrsr && pCrsr->GetPrev() != 0) { - if( pCrsr->GetPrev() != pCrsr && pCrsr->GetPrev() != 0) - { - pCrsr = (SwPaM*)pCrsr->GetPrev(); - bForwardSelection = (*pCrsr->GetPoint()) > (*pCrsr->GetMark()); - bHasSelection = true; - pCrsr->DeleteMark(); - pCrsr->SetMark(); - rWrtShell.KillPams(); - pCrsr = rWrtShell.GetCrsr(); - } + // if cursor have multiple selections + + // clear all the selections except the last + rWrtShell.KillPams(); + + // reset the cursor to the remaining selection + pCrsr = rWrtShell.GetCrsr(); + bHasSelection = true; } - else + + bool dontMove = false; + if (bHasSelection) + { bForwardSelection = (*pCrsr->GetPoint()) > (*pCrsr->GetMark()); - pCrsr->DeleteMark(); - pCrsr->SetMark(); - if( !bHasSelection && rWrtShell.IsInRightToLeftText() ) - bForwardSelection = !bForwardSelection; + // clear the selection leaving just the cursor + pCrsr->DeleteMark(); + pCrsr->SetMark(); + } + else + { + bool rightToLeft = rWrtShell.IsInRightToLeftText(); + // if there were no selection (only a cursor) and that the cursor were at the end of the paragraph + // then don't move + if ( rWrtShell.IsEndPara() && !rightToLeft ) + dontMove = true; + + // revert left and right + if ( rightToLeft ) + { + if (pCrsr->GetPoint()->nContent == 0) + dontMove = true; + else + bForwardSelection = !bForwardSelection; + } + } - if( !( !bHasSelection && rWrtShell.IsEndPara() ) ) + // move the cursor in order to select one charactere + if (!dontMove) pCrsr->Move( bForwardSelection ? fnMoveBackward : fnMoveForward ); } - if(pItemSet) + if(pItemSet_TxtAttr) { if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) ) - rWrtShell.GetFlyFrmAttr(*pItemSet); + rWrtShell.GetFlyFrmAttr(*pItemSet_TxtAttr); else { - rWrtShell.GetCurAttr(*pItemSet); + // get the text attributs from named and automatic formating + rWrtShell.GetCurAttr(*pItemSet_TxtAttr); - // additional numbering properties for paragraph styles - if( nSelectionType & nsSelectionType::SEL_TXT && rWrtShell.GetCurNumRule() ) + if( nSelectionType & nsSelectionType::SEL_TXT ) { - SfxBoolItem aStart(FN_NUMBER_NEWSTART, rWrtShell.IsNumRuleStart()); - pItemSet->Put(aStart); - SfxUInt16Item aStartAt(FN_NUMBER_NEWSTART_AT, rWrtShell.GetNodeNumStart()); - pItemSet->Put(aStartAt); + // get the paragraphe attribut (could be charactere properties) + // from named and automatic formating + rWrtShell.GetCurParAttr(*pItemSet_ParAttr); } } } @@ -385,37 +391,56 @@ void SwFormatClipboard::Copy( SwWrtShell& rWrtShell, SfxItemPool& rPool, bool bP sal_Bool bOnlyHardAttr = sal_True; if( pDrawView->AreObjectsMarked() ) { - pItemSet = new SfxItemSet( pDrawView->GetAttrFromMarked(bOnlyHardAttr) ); + pItemSet_TxtAttr = new SfxItemSet( pDrawView->GetAttrFromMarked(bOnlyHardAttr) ); //remove attributes defining the type/data of custom shapes - pItemSet->ClearItem(SDRATTR_CUSTOMSHAPE_ENGINE); - pItemSet->ClearItem(SDRATTR_CUSTOMSHAPE_DATA); - pItemSet->ClearItem(SDRATTR_CUSTOMSHAPE_GEOMETRY); - pItemSet->ClearItem(SDRATTR_CUSTOMSHAPE_REPLACEMENT_URL); + pItemSet_TxtAttr->ClearItem(SDRATTR_CUSTOMSHAPE_ENGINE); + pItemSet_TxtAttr->ClearItem(SDRATTR_CUSTOMSHAPE_DATA); + pItemSet_TxtAttr->ClearItem(SDRATTR_CUSTOMSHAPE_GEOMETRY); + pItemSet_TxtAttr->ClearItem(SDRATTR_CUSTOMSHAPE_REPLACEMENT_URL); } } } + if( nSelectionType & nsSelectionType::SEL_TBL_CELLS )//only copy table attributes if really cells are selected (not only text in tables) { - m_pTableItemSet = lcl_CreateEmptyItemSet( nsSelectionType::SEL_TBL, rPool ); + m_pTableItemSet = new SfxItemSet(rPool, + SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_SHADOW, //SID_ATTR_BORDER_OUTER is inbetween + RES_BACKGROUND, RES_SHADOW, //RES_BOX is inbetween + SID_ATTR_BRUSH_ROW, SID_ATTR_BRUSH_TABLE, + RES_BREAK, RES_BREAK, + RES_PAGEDESC, RES_PAGEDESC, + RES_LAYOUT_SPLIT, RES_LAYOUT_SPLIT, + RES_ROW_SPLIT, RES_ROW_SPLIT, + RES_KEEP, RES_KEEP, + RES_FRAMEDIR, RES_FRAMEDIR, + FN_PARAM_TABLE_HEADLINE, FN_PARAM_TABLE_HEADLINE, + FN_TABLE_BOX_TEXTORIENTATION, FN_TABLE_BOX_TEXTORIENTATION, + FN_TABLE_SET_VERT_ALIGN, FN_TABLE_SET_VERT_ALIGN, + 0); lcl_getTableAttributes( *m_pTableItemSet, rWrtShell ); } m_nSelectionType = nSelectionType; - m_pItemSet = pItemSet; + m_pItemSet_TxtAttr = pItemSet_TxtAttr; + m_pItemSet_ParAttr = pItemSet_ParAttr; if( nSelectionType & nsSelectionType::SEL_TXT ) { + // if text is selected save the named character format SwFmt* pFmt = rWrtShell.GetCurCharFmt(); if( pFmt ) m_aCharStyle = pFmt->GetName(); + // and the named paragraph format pFmt = rWrtShell.GetCurTxtFmtColl(); if( pFmt ) m_aParaStyle = pFmt->GetName(); } + rWrtShell.Pop(sal_False); rWrtShell.EndAction(); } + typedef boost::shared_ptr< SfxPoolItem > SfxPoolItemSharedPtr; typedef std::vector< SfxPoolItemSharedPtr > ItemVector; // collect all PoolItems from the applied styles @@ -436,10 +461,10 @@ void lcl_AppendSetItems( ItemVector& rItemVector, const SfxItemSet& rStyleAttrSe } } // remove all items that are inherited from the styles -void lcl_RemoveEqualItems( SfxItemSet& rTemplateItemSet, ItemVector& rItemVector ) +void lcl_RemoveEqualItems( SfxItemSet& rTemplateItemSet, const ItemVector& rItemVector ) { - ItemVector::iterator aEnd = rItemVector.end(); - ItemVector::iterator aIter = rItemVector.begin(); + ItemVector::const_iterator aEnd = rItemVector.end(); + ItemVector::const_iterator aIter = rItemVector.begin(); while( aIter != aEnd ) { const SfxPoolItem* pItem; @@ -467,35 +492,77 @@ void SwFormatClipboard::Paste( SwWrtShell& rWrtShell, SfxStyleSheetBasePool* pPo rWrtShell.StartUndo(UNDO_INSATTR); ItemVector aItemVector; - if(pPool) //to find the styles we need the pool + + if( nSelectionType & nsSelectionType::SEL_TXT ) { - if( nSelectionType & nsSelectionType::SEL_TXT ) + // apply the named text and paragraphe formating + if( pPool ) { + // if there is a named text format recorded and the user want to apply it if(m_aCharStyle.Len() && !bNoCharacterFormats ) { - SwDocStyleSheet* pStyle = (SwDocStyleSheet*)pPool->Find(m_aCharStyle, SFX_STYLE_FAMILY_CHAR); + // look for the named text format in the pool + SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>(pPool->Find(m_aCharStyle, SFX_STYLE_FAMILY_CHAR)); + + // if the style is found if( pStyle ) { SwFmtCharFmt aFmt(pStyle->GetCharFmt()); - // collect items from character style + // store the attributs from this style in aItemVector in order + // not to apply them as automatic formating attributs later in the code lcl_AppendSetItems( aItemVector, aFmt.GetCharFmt()->GetAttrSet()); - sal_uInt16 nFlags=0; - rWrtShell.SetAttr( aFmt, nFlags ); + + // apply the named format + rWrtShell.SetAttr( aFmt ); } } + + // if there is a named paragraph format recorded and the user want to apply it if(m_aParaStyle.Len() && !bNoParagraphFormats ) { - SwDocStyleSheet* pStyle = (SwDocStyleSheet*)pPool->Find(m_aParaStyle, SFX_STYLE_FAMILY_PARA); + // look for the named pragraph format in the pool + SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>(pPool->Find(m_aParaStyle, SFX_STYLE_FAMILY_PARA)); if( pStyle ) { - // collect items from paragraph style + // store the attributs from this style in aItemVector in order + // not to apply them as automatic formating attributs later in the code lcl_AppendSetItems( aItemVector, pStyle->GetCollection()->GetAttrSet()); + + // apply the named format rWrtShell.SetTxtFmtColl( pStyle->GetCollection() ); } } } + + // apply the paragraphe automatic attributs + if ( m_pItemSet_ParAttr && m_pItemSet_ParAttr->Count() != 0 && !bNoParagraphFormats ) + { + // temporary SfxItemSet + SfxItemSet* pTemplateItemSet = lcl_CreateEmptyItemSet( + nSelectionType, *m_pItemSet_ParAttr->GetPool(), false); + // no need to verify the existance of pTemplateItemSet as we + // know that here the selection type is SEL_TXT + + pTemplateItemSet->Put( *m_pItemSet_ParAttr ); + + // remove attribut that were applied by named text and paragraph formating + lcl_RemoveEqualItems( *pTemplateItemSet, aItemVector ); + + // it can't be a multiple selection + SwPaM* pCrsr = rWrtShell.GetCrsr(); + + // apply the paragraphe automatic attributs + pCrsr->GetCntntNode()->SetAttr( *pTemplateItemSet ); + + // store the attributs in aItemVector in order not to apply them as + // text automatic formating attributs later in the code + lcl_AppendSetItems( aItemVector, *pTemplateItemSet); + + delete pTemplateItemSet; + } } - if(m_pItemSet) + + if(m_pItemSet_TxtAttr) { if( nSelectionType & nsSelectionType::SEL_DRW ) { @@ -503,50 +570,30 @@ void SwFormatClipboard::Paste( SwWrtShell& rWrtShell, SfxStyleSheetBasePool* pPo if(pDrawView) { sal_Bool bReplaceAll = sal_True; - pDrawView->SetAttrToMarked(*m_pItemSet, bReplaceAll); + pDrawView->SetAttrToMarked(*m_pItemSet_TxtAttr, bReplaceAll); } } else { + // temporary SfxItemSet SfxItemSet* pTemplateItemSet = lcl_CreateEmptyItemSet( - nSelectionType, *m_pItemSet->GetPool() - , bNoCharacterFormats, bNoParagraphFormats ); + nSelectionType, *m_pItemSet_TxtAttr->GetPool(), true ); + if(pTemplateItemSet) { - pTemplateItemSet->Put( *m_pItemSet ); - // only _set_ attributes that differ from style attributes should be applied - the style is applied anyway + // copy the stored automatic texte attributs in a temporary SfxItemSet + pTemplateItemSet->Put( *m_pItemSet_TxtAttr ); + + // only attributes that were not apply by named style attributes and automatic + // paragraphe attributes should be applied lcl_RemoveEqualItems( *pTemplateItemSet, aItemVector ); + // apply the charactere automatic attributs if( nSelectionType & (nsSelectionType::SEL_FRM | nsSelectionType::SEL_OLE | nsSelectionType::SEL_GRF) ) rWrtShell.SetFlyFrmAttr(*pTemplateItemSet); - else - { + else if ( !bNoCharacterFormats ) rWrtShell.SetAttr(*pTemplateItemSet); - // additional numbering properties for paragraph styles - if( nSelectionType & nsSelectionType::SEL_TXT && rWrtShell.GetCurNumRule() ) - { - if( SFX_ITEM_SET == pTemplateItemSet->GetItemState(FN_NUMBER_NEWSTART) ) - { - sal_Bool bStart = ((SfxBoolItem&)pTemplateItemSet->Get(FN_NUMBER_NEWSTART)).GetValue(); - sal_uInt16 nNumStart = USHRT_MAX; - if( SFX_ITEM_SET == pTemplateItemSet->GetItemState(FN_NUMBER_NEWSTART_AT) ) - { - nNumStart = ((SfxUInt16Item&)pTemplateItemSet->Get(FN_NUMBER_NEWSTART_AT)).GetValue(); - if(USHRT_MAX != nNumStart) - bStart = sal_False; - } - rWrtShell.SetNumRuleStart(bStart); - rWrtShell.SetNodeNumStart(nNumStart); - } - else if( SFX_ITEM_SET == pTemplateItemSet->GetItemState(FN_NUMBER_NEWSTART_AT) ) - { - sal_uInt16 nNumStart = ((SfxUInt16Item&)pTemplateItemSet->Get(FN_NUMBER_NEWSTART_AT)).GetValue(); - rWrtShell.SetNodeNumStart(nNumStart); - rWrtShell.SetNumRuleStart(sal_False); - } - } - } delete pTemplateItemSet; } } @@ -566,8 +613,11 @@ void SwFormatClipboard::Erase() { m_nSelectionType = 0; - delete m_pItemSet; - m_pItemSet = 0; + delete m_pItemSet_TxtAttr; + m_pItemSet_TxtAttr = 0; + + delete m_pItemSet_ParAttr; + m_pItemSet_ParAttr = 0; delete m_pTableItemSet; m_pTableItemSet = 0; -- 1.7.9.4
Attachment:
signature.asc
Description: This is a digitally signed message part