1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <unocrsr.hxx>
#include <doc.hxx>
#include <IDocumentLayoutAccess.hxx>
#include <swtable.hxx>
#include <rootfrm.hxx>
sw::UnoCursorHint::~UnoCursorHint() {}
SwUnoCursor::SwUnoCursor( const SwPosition &rPos )
: SwCursor( rPos, nullptr )
, m_bRemainInSection(true)
, m_bSkipOverHiddenSections(false)
, m_bSkipOverProtectSections(false)
{}
SwUnoCursor::~SwUnoCursor()
{
SwDoc& rDoc = GetDoc();
if( !rDoc.IsInDtor() )
{
assert(!m_aNotifier.HasListeners());
}
// delete the whole ring
while( GetNext() != this )
{
Ring* pNxt = GetNextInRing();
pNxt->MoveTo(nullptr); // remove from chain
delete pNxt; // and delete
}
}
bool SwUnoCursor::IsReadOnlyAvailable() const
{
return true;
}
const SwContentFrame*
SwUnoCursor::DoSetBidiLevelLeftRight( bool &, bool, bool )
{
return nullptr; // not for uno cursor
}
void SwUnoCursor::DoSetBidiLevelUpDown()
{
// not for uno cursor
}
bool SwUnoCursor::IsSelOvr( SwCursorSelOverFlags eFlags )
{
if (m_bRemainInSection)
{
SwDoc& rDoc = GetDoc();
SwNodeIndex aOldIdx( *rDoc.GetNodes()[ GetSavePos()->nNode ] );
SwNodeIndex& rPtIdx = GetPoint()->nNode;
SwStartNode *pOldSttNd = aOldIdx.GetNode().StartOfSectionNode(),
*pNewSttNd = rPtIdx.GetNode().StartOfSectionNode();
if( pOldSttNd != pNewSttNd )
{
bool bMoveDown = GetSavePos()->nNode < rPtIdx.GetIndex();
bool bValidPos = false;
// search the correct surrounded start node - which the index
// can't leave.
while( pOldSttNd->IsSectionNode() )
pOldSttNd = pOldSttNd->StartOfSectionNode();
// is the new index inside this surrounded section?
if( rPtIdx > *pOldSttNd &&
rPtIdx < pOldSttNd->EndOfSectionIndex() )
{
// check if it a valid move inside this section
// (only over SwSection's !)
const SwStartNode* pInvalidNode;
do {
pInvalidNode = nullptr;
pNewSttNd = rPtIdx.GetNode().StartOfSectionNode();
const SwStartNode *pSttNd = pNewSttNd, *pEndNd = pOldSttNd;
if( pSttNd->EndOfSectionIndex() >
pEndNd->EndOfSectionIndex() )
{
pEndNd = pNewSttNd;
pSttNd = pOldSttNd;
}
while( pSttNd->GetIndex() > pEndNd->GetIndex() )
{
if( !pSttNd->IsSectionNode() )
pInvalidNode = pSttNd;
pSttNd = pSttNd->StartOfSectionNode();
}
if( pInvalidNode )
{
if( bMoveDown )
{
rPtIdx.Assign( *pInvalidNode->EndOfSectionNode(), 1 );
if( !rPtIdx.GetNode().IsContentNode() &&
( !rDoc.GetNodes().GoNextSection( &rPtIdx ) ||
rPtIdx > pOldSttNd->EndOfSectionIndex() ) )
break;
}
else
{
rPtIdx.Assign( *pInvalidNode, -1 );
if( !rPtIdx.GetNode().IsContentNode() &&
( !SwNodes::GoPrevSection( &rPtIdx ) ||
rPtIdx < *pOldSttNd ) )
break;
}
}
else
bValidPos = true;
} while ( pInvalidNode );
}
if( bValidPos )
{
SwContentNode* pCNd = GetContentNode();
GetPoint()->nContent.Assign( pCNd, (pCNd && !bMoveDown) ? pCNd->Len() : 0);
}
else
{
rPtIdx = GetSavePos()->nNode;
GetPoint()->nContent.Assign( GetContentNode(), GetSavePos()->nContent );
return true;
}
}
}
return SwCursor::IsSelOvr( eFlags );
}
SwUnoTableCursor::SwUnoTableCursor(const SwPosition& rPos)
: SwCursor(rPos, nullptr)
, SwUnoCursor(rPos)
, SwTableCursor(rPos)
, m_aTableSel(rPos, nullptr)
{
SetRemainInSection(false);
}
SwUnoTableCursor::~SwUnoTableCursor()
{
while (m_aTableSel.GetNext() != &m_aTableSel)
delete m_aTableSel.GetNext();
}
bool SwUnoTableCursor::IsSelOvr( SwCursorSelOverFlags eFlags )
{
bool bRet = SwUnoCursor::IsSelOvr( eFlags );
if( !bRet )
{
const SwTableNode* pTNd = GetPoint()->nNode.GetNode().FindTableNode();
bRet = !(pTNd == GetDoc().GetNodes()[ GetSavePos()->nNode ]->
FindTableNode() && (!HasMark() ||
pTNd == GetMark()->nNode.GetNode().FindTableNode() ));
}
return bRet;
}
void SwUnoTableCursor::MakeBoxSels()
{
const SwContentNode* pCNd;
bool bMakeTableCursors = true;
if( GetPoint()->nNode.GetIndex() && GetMark()->nNode.GetIndex() &&
nullptr != ( pCNd = GetContentNode() ) && pCNd->getLayoutFrame( pCNd->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout() ) &&
nullptr != ( pCNd = GetContentNode(false) ) && pCNd->getLayoutFrame( pCNd->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout() ) )
bMakeTableCursors = GetDoc().getIDocumentLayoutAccess().GetCurrentLayout()->MakeTableCursors( *this );
if ( !bMakeTableCursors )
{
SwSelBoxes const& rTmpBoxes = GetSelectedBoxes();
while (!rTmpBoxes.empty())
{
DeleteBox(0);
}
}
if( IsChgd() )
{
SwTableCursor::MakeBoxSels( &m_aTableSel );
if (!GetSelectedBoxesCount())
{
const SwTableBox* pBox;
const SwNode* pBoxNd = GetPoint()->nNode.GetNode().FindTableBoxStartNode();
const SwTableNode* pTableNd = pBoxNd ? pBoxNd->FindTableNode() : nullptr;
if( pTableNd && nullptr != ( pBox = pTableNd->GetTable().GetTableBox( pBoxNd->GetIndex() )) )
InsertBox( *pBox );
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|