summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2014-04-28 18:03:49 +0200
committerLuboš Luňák <l.lunak@centrum.cz>2014-04-29 12:32:54 +0200
commit7d6c40d7a7df2051cbc831b8c118a2313d37cc17 (patch)
tree065f2e5253898edd34445b2c414d583ba85d94ec
parent3fdf7e0032d0674d4b691068da53ee712d70750d (diff)
allow accepting/rejecting changes in a selection (bnc#874790)
More convenient than handling them one by one.
-rw-r--r--sw/inc/docary.hxx10
-rw-r--r--sw/inc/editsh.hxx2
-rw-r--r--sw/source/core/doc/docredln.cxx65
-rw-r--r--sw/source/core/edit/edredln.cxx18
-rw-r--r--sw/source/ui/uiview/view2.cxx31
-rw-r--r--sw/source/ui/uiview/viewstat.cxx37
6 files changed, 115 insertions, 48 deletions
diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx
index 6b9636ee27fd..dc04113cc3a1 100644
--- a/sw/inc/docary.hxx
+++ b/sw/inc/docary.hxx
@@ -38,6 +38,7 @@ class SwUnoCrsr;
class SwOLENode;
class SwTxtFmtColl;
class SwGrfFmtColl;
+class SwPosition;
namespace com { namespace sun { namespace star { namespace i18n {
struct ForbiddenCharacters; ///< comes from the I18N UNO interface
@@ -172,6 +173,15 @@ public:
sal_uInt16 FindPrevSeqNo( sal_uInt16 nSeqNo, sal_uInt16 nSttPos,
sal_uInt16 nLookahead = 20 ) const;
+ /**
+ Find the redline at the given position.
+
+ @param tableIndex position in SwRedlineTbl to start searching at, will be updated with the index of the returned
+ redline (or the next redline after the given position if not found)
+ @param next true: redline starts at position and ends after, false: redline starts before position and ends at or after
+ */
+ const SwRedline* FindAtPosition( const SwPosition& startPosition, sal_uInt16& tableIndex, bool next = true ) const;
+
using _SwRedlineTbl::size;
using _SwRedlineTbl::operator[];
using _SwRedlineTbl::empty;
diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx
index 6e4972193a7f..904124fe3beb 100644
--- a/sw/inc/editsh.hxx
+++ b/sw/inc/editsh.hxx
@@ -900,6 +900,8 @@ public:
const SwRedline& GetRedline( sal_uInt16 nPos ) const;
sal_Bool AcceptRedline( sal_uInt16 nPos );
sal_Bool RejectRedline( sal_uInt16 nPos );
+ bool AcceptRedlinesInSelection();
+ bool RejectRedlinesInSelection();
/** Search Redline for this Data and @return position in array.
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index 9a2ea578ecd0..58beba38b356 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -1919,36 +1919,6 @@ static sal_Bool lcl_RejectRedline( SwRedlineTbl& rArr, sal_uInt16& rPos,
return bRet;
}
-
-static const SwRedline* lcl_FindCurrRedline( const SwPosition& rSttPos,
- sal_uInt16& rPos,
- bool bNext = true )
-{
- const SwRedline* pFnd = 0;
- const SwRedlineTbl& rArr = rSttPos.nNode.GetNode().GetDoc()->GetRedlineTbl();
- for( ; rPos < rArr.size() ; ++rPos )
- {
- const SwRedline* pTmp = rArr[ rPos ];
- if( pTmp->HasMark() && pTmp->IsVisible() )
- {
- const SwPosition* pRStt = pTmp->Start(),
- * pREnd = pRStt == pTmp->GetPoint() ? pTmp->GetMark()
- : pTmp->GetPoint();
- if( bNext ? *pRStt <= rSttPos : *pRStt < rSttPos )
- {
- if( bNext ? *pREnd > rSttPos : *pREnd >= rSttPos )
- {
- pFnd = pTmp;
- break;
- }
- }
- else
- break;
- }
- }
- return pFnd;
-}
-
static int lcl_AcceptRejectRedl( Fn_AcceptReject fn_AcceptReject,
SwRedlineTbl& rArr, sal_Bool bCallDelete,
const SwPaM& rPam)
@@ -1959,7 +1929,7 @@ static int lcl_AcceptRejectRedl( Fn_AcceptReject fn_AcceptReject,
const SwPosition* pStt = rPam.Start(),
* pEnd = pStt == rPam.GetPoint() ? rPam.GetMark()
: rPam.GetPoint();
- const SwRedline* pFnd = lcl_FindCurrRedline( *pStt, n, true );
+ const SwRedline* pFnd = rArr.FindAtPosition( *pStt, n, true );
if( pFnd && // Is new a part of it?
( *pFnd->Start() != *pStt || *pFnd->End() > *pEnd ))
{
@@ -2264,7 +2234,7 @@ const SwRedline* SwDoc::SelNextRedline( SwPaM& rPam ) const
// If the starting positon points to the last valid ContentNode,
// we take the next Redline in any case.
sal_uInt16 n = 0;
- const SwRedline* pFnd = lcl_FindCurrRedline( rSttPos, n, true );
+ const SwRedline* pFnd = GetRedlineTbl().FindAtPosition( rSttPos, n, true );
if( pFnd )
{
const SwPosition* pEnd = pFnd->End();
@@ -2381,7 +2351,7 @@ const SwRedline* SwDoc::SelPrevRedline( SwPaM& rPam ) const
// If the starting positon points to the last valid ContentNode,
// we take the previous Redline in any case.
sal_uInt16 n = 0;
- const SwRedline* pFnd = lcl_FindCurrRedline( rSttPos, n, false );
+ const SwRedline* pFnd = GetRedlineTbl().FindAtPosition( rSttPos, n, false );
if( pFnd )
{
const SwPosition* pStt = pFnd->Start();
@@ -2496,7 +2466,7 @@ bool SwDoc::SetRedlineComment( const SwPaM& rPaM, const String& rS )
* pEnd = pStt == rPaM.GetPoint() ? rPaM.GetMark()
: rPaM.GetPoint();
sal_uInt16 n = 0;
- if( lcl_FindCurrRedline( *pStt, n, true ) )
+ if( GetRedlineTbl().FindAtPosition( *pStt, n, true ) )
{
for( ; n < mpRedlineTbl->size(); ++n )
{
@@ -2833,6 +2803,33 @@ sal_uInt16 SwRedlineTbl::FindPrevSeqNo( sal_uInt16 nSeqNo, sal_uInt16 nSttPos,
return nRet;
}
+const SwRedline* SwRedlineTbl::FindAtPosition( const SwPosition& rSttPos,
+ sal_uInt16& rPos,
+ bool bNext ) const
+{
+ const SwRedline* pFnd = 0;
+ for( ; rPos < size() ; ++rPos )
+ {
+ const SwRedline* pTmp = (*this)[ rPos ];
+ if( pTmp->HasMark() && pTmp->IsVisible() )
+ {
+ const SwPosition* pRStt = pTmp->Start(),
+ * pREnd = pRStt == pTmp->GetPoint() ? pTmp->GetMark()
+ : pTmp->GetPoint();
+ if( bNext ? *pRStt <= rSttPos : *pRStt < rSttPos )
+ {
+ if( bNext ? *pREnd > rSttPos : *pREnd >= rSttPos )
+ {
+ pFnd = pTmp;
+ break;
+ }
+ }
+ else
+ break;
+ }
+ }
+ return pFnd;
+}
SwRedlineExtraData::~SwRedlineExtraData()
{
diff --git a/sw/source/core/edit/edredln.cxx b/sw/source/core/edit/edredln.cxx
index dbefb53cd806..f532ecce33b1 100644
--- a/sw/source/core/edit/edredln.cxx
+++ b/sw/source/core/edit/edredln.cxx
@@ -92,6 +92,24 @@ sal_Bool SwEditShell::RejectRedline( sal_uInt16 nPos )
return bRet;
}
+bool SwEditShell::AcceptRedlinesInSelection()
+{
+ SET_CURR_SHELL( this );
+ StartAllAction();
+ sal_Bool bRet = GetDoc()->AcceptRedline( *GetCrsr(), true );
+ EndAllAction();
+ return bRet;
+}
+
+bool SwEditShell::RejectRedlinesInSelection()
+{
+ SET_CURR_SHELL( this );
+ StartAllAction();
+ sal_Bool bRet = GetDoc()->RejectRedline( *GetCrsr(), true );
+ EndAllAction();
+ return bRet;
+}
+
// Set the comment at the Redline
sal_Bool SwEditShell::SetRedlineComment( const String& rS )
{
diff --git a/sw/source/ui/uiview/view2.cxx b/sw/source/ui/uiview/view2.cxx
index 744428ca716a..f4af4366d4e5 100644
--- a/sw/source/ui/uiview/view2.cxx
+++ b/sw/source/ui/uiview/view2.cxx
@@ -639,22 +639,31 @@ void SwView::Execute(SfxRequest &rReq)
case FN_REDLINE_ACCEPT_DIRECT:
case FN_REDLINE_REJECT_DIRECT:
{
- // We check for a redline at the start of the selection/cursor, not the point.
- // This ensures we work properly with FN_REDLINE_NEXT_CHANGE, which leaves the
- // point at the *end* of the redline and the mark at the start (so GetRedline
- // would return NULL if called on the point)
SwDoc *pDoc = m_pWrtShell->GetDoc();
SwPaM *pCursor = m_pWrtShell->GetCrsr();
-
- sal_uInt16 nRedline = 0;
- const SwRedline *pRedline = pDoc->GetRedline(*pCursor->Start(), &nRedline);
- assert(pRedline != 0);
- if (pRedline)
+ if( pCursor->HasMark())
{
if (FN_REDLINE_ACCEPT_DIRECT == nSlot)
- m_pWrtShell->AcceptRedline(nRedline);
+ m_pWrtShell->AcceptRedlinesInSelection();
else
- m_pWrtShell->RejectRedline(nRedline);
+ m_pWrtShell->RejectRedlinesInSelection();
+ }
+ else
+ {
+ // We check for a redline at the start of the selection/cursor, not the point.
+ // This ensures we work properly with FN_REDLINE_NEXT_CHANGE, which leaves the
+ // point at the *end* of the redline and the mark at the start (so GetRedline
+ // would return NULL if called on the point)
+ sal_uInt16 nRedline = 0;
+ const SwRedline *pRedline = pDoc->GetRedline(*pCursor->Start(), &nRedline);
+ assert(pRedline != 0);
+ if (pRedline)
+ {
+ if (FN_REDLINE_ACCEPT_DIRECT == nSlot)
+ m_pWrtShell->AcceptRedline(nRedline);
+ else
+ m_pWrtShell->RejectRedline(nRedline);
+ }
}
}
break;
diff --git a/sw/source/ui/uiview/viewstat.cxx b/sw/source/ui/uiview/viewstat.cxx
index 21aa946afce2..fc25af13fd6b 100644
--- a/sw/source/ui/uiview/viewstat.cxx
+++ b/sw/source/ui/uiview/viewstat.cxx
@@ -52,6 +52,8 @@
#include <svl/stritem.hxx>
#include <unotools/moduleoptions.hxx>
#include <svl/visitem.hxx>
+#include <redline.hxx>
+#include <docary.hxx>
#include <cmdid.h>
@@ -266,12 +268,41 @@ void SwView::GetState(SfxItemSet &rSet)
case FN_REDLINE_ACCEPT_DIRECT:
case FN_REDLINE_REJECT_DIRECT:
{
- // If the selection/cursor start position isn't on a redline, disable
- // accepting/rejecting changes.
SwDoc *pDoc = m_pWrtShell->GetDoc();
SwPaM *pCursor = m_pWrtShell->GetCrsr();
- if (0 == pDoc->GetRedline(*pCursor->Start(), 0))
+ if (GetDocShell()->HasChangeRecordProtection())
rSet.DisableItem(nWhich);
+ else if (pCursor->HasMark())
+ { // If the selection does not contain redlines, disable accepting/rejecting changes.
+ sal_uInt16 index = 0;
+ const SwRedlineTbl& table = pDoc->GetRedlineTbl();
+ const SwRedline* redline = table.FindAtPosition( *pCursor->Start(), index );
+ if( redline != NULL && *redline->Start() == *pCursor->End())
+ redline = NULL;
+ if( redline == NULL )
+ {
+ for(; index < table.size(); ++index )
+ {
+ const SwRedline* tmp = table[ index ];
+ if( *tmp->Start() >= *pCursor->End())
+ break;
+ if( tmp->HasMark() && tmp->IsVisible())
+ {
+ redline = tmp;
+ break;
+ }
+ }
+ }
+ if( redline == NULL )
+ rSet.DisableItem(nWhich);
+ }
+ else
+ {
+ // If the cursor position isn't on a redline, disable
+ // accepting/rejecting changes.
+ if (0 == pDoc->GetRedline(*pCursor->Start(), 0))
+ rSet.DisableItem(nWhich);
+ }
}
break;