/* -*- 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 .
*/
// the returned SwGrfNode pointer is used in GetGraphic() and GetGraphicSize()
SwGrfNode * SwEditShell::GetGrfNode_() const
{
SwGrfNode *pGrfNode = nullptr;
SwPaM* pCursor = GetCursor(); if( !pCursor->HasMark() ||
pCursor->GetPoint()->GetNode() == pCursor->GetMark()->GetNode() )
pGrfNode = pCursor->GetPoint()->GetNode().GetGrfNode();
return pGrfNode;
}
// returns a Graphic pointer if CurrentCursor->GetPoint() points to a SwGrfNode and // GetMark is not set or points to the same Graphic const Graphic* SwEditShell::GetGraphic( bool bWait ) const
{
SwGrfNode* pGrfNode = GetGrfNode_(); const Graphic* pGrf( nullptr ); if ( pGrfNode )
{
pGrf = &(pGrfNode->GetGrf(bWait && GraphicType::Default == pGrfNode->GetGrf().GetType()));
} return pGrf;
}
// returns the size of a graphic in <rSz> if CurrentCursor->GetPoint() points to a SwGrfNode and // GetMark is not set or points to the same graphic bool SwEditShell::GetGrfSize(Size& rSz) const
{
SwNoTextNode* pNoTextNd;
SwPaM* pCurrentCursor = GetCursor(); if( ( !pCurrentCursor->HasMark()
|| pCurrentCursor->GetPoint()->GetNode() == pCurrentCursor->GetMark()->GetNode() )
&& nullptr != ( pNoTextNd = pCurrentCursor->GetPointNode().GetNoTextNode() ) )
{
rSz = pNoTextNd->GetTwipSize(); returntrue;
} returnfalse;
}
/// Read again if graphic is not OK and replace old one void SwEditShell::ReRead( const OUString& rGrfName, const OUString& rFltName, const Graphic* pGraphic )
{
StartAllAction();
mxDoc->getIDocumentContentOperations().ReRead( *GetCursor(), rGrfName, rFltName, pGraphic );
EndAllAction();
}
/// Returns the name and the filter name of a graphic if the pointer is on a graphic. /// If a String-pointer is != 0 then return corresponding name. void SwEditShell::GetGrfNms( OUString* pGrfName, OUString* pFltName ) const
{
OSL_ENSURE( pGrfName || pFltName, "No parameters" );
SwGrfNode *pGrfNode = GetGrfNode_(); if( pGrfNode && pGrfNode->IsLinkedFile() )
pGrfNode->GetFileFilterNms( pGrfName, pFltName );
}
/** Get OLE object at pointer. * * Returns a pointer to a SvInPlaceObjectRef if CurrentCursor->GetPoint() points to a SwOLENode and * GetMark is not set or points to the same object reference. Gets this pointer from the Doc * if the object should be searched by name.
*/
svt::EmbeddedObjectRef& SwEditShell::GetOLEObject() const
{
OSL_ENSURE( CNT_OLE == GetCntType(), "GetOLEObj: no OLENode." );
OSL_ENSURE( !GetCursor()->HasMark() ||
(GetCursor()->HasMark() &&
GetCursor()->GetPoint()->GetNode() == GetCursor()->GetMark()->GetNode()), "GetOLEObj: no OLENode." );
/// get the reference of a given name in the Doc const SwFormatRefMark* SwEditShell::GetRefMark( const SwMarkName& rName ) const
{ return GetDoc()->GetRefMark( rName );
}
/// get the names of all references in a Doc
sal_uInt16 SwEditShell::GetRefMarks( std::vector<OUString>* pStrings ) const
{ return GetDoc()->GetRefMarks( pStrings );
}
OUString SwEditShell::GetDropText( const sal_Int32 nChars ) const
{ /* * pb: made changes for #i74939# * * always return a string even though there is a selection
*/
OUString aText;
SwPaM* pCursor = GetCursor(); if ( IsMultiSelection() )
{ // if a multi selection exists, search for the first line // -> it is the cursor with the lowest index
SwNodeOffset nIndex = pCursor->GetMark()->GetNodeIndex(); bool bPrev = true;
SwPaM* pLast = pCursor;
SwPaM* pTemp = pCursor; while ( bPrev )
{
SwPaM* pPrev2 = pTemp->GetPrev();
bPrev = ( pPrev2 && pPrev2 != pLast ); if ( bPrev )
{
pTemp = pPrev2;
SwNodeOffset nTemp = pPrev2->GetMark()->GetNodeIndex(); if ( nTemp < nIndex )
{
nIndex = nTemp;
pCursor = pPrev2;
}
}
}
}
void *SwEditShell::GetIMapInventor() const
{ // The node on which the cursor points should be sufficient as a unique identifier returnstatic_cast<void*>(&(GetCursor()->GetPointNode()));
}
/// If the cursor is in an INetAttribute then it will be deleted completely (incl. hint text, the /// latter is needed for drag & drop) void SwEditShell::DelINetAttrWithText()
{ bool bRet = SelectTextAttr( RES_TXTATR_INETFMT, false ); if( bRet )
DeleteSel(*GetCursor(), true);
}
/// Set the DontExpand flag at the text character attributes bool SwEditShell::DontExpandFormat()
{ bool bRet = false; if( !IsTableMode() && GetDoc()->DontExpandFormat( *GetCursor()->GetPoint() ))
{
bRet = true;
CallChgLnk();
} return bRet;
}
void SwEditShell::SetNumberingRestart()
{
StartAllAction();
Push(); // iterate over all text contents - body, frames, header, footer, footnote text
SwPaM* pCursor = GetCursor(); for(int i = 0; i < 2; i++)
{ if(!i)
MakeFindRange(SwDocPositions::Start, SwDocPositions::End, pCursor); // body content else
MakeFindRange(SwDocPositions::OtherStart, SwDocPositions::OtherEnd, pCursor); // extra content
SwPosition* pSttPos = pCursor->Start(), *pEndPos = pCursor->End();
SwNodeOffset nCurrNd = pSttPos->GetNodeIndex();
SwNodeOffset nEndNd = pEndPos->GetNodeIndex(); if( nCurrNd <= nEndNd )
{
SwContentFrame* pContentFrame; bool bGoOn = true; // iterate over all paragraphs while( bGoOn )
{
SwNode* pNd = GetDoc()->GetNodes()[ nCurrNd ]; switch( pNd->GetNodeType() )
{ case SwNodeType::Text:
pContentFrame = static_cast<SwTextNode*>(pNd)->getLayoutFrame( GetLayout() ); if( nullptr != pContentFrame )
{ // skip hidden frames - ignore protection! if( !pContentFrame->IsHiddenNow() )
{ // if the node is numbered and the starting value of the numbering equals the // start value of the numbering rule then set this value as hard starting value
// get the node num // OD 2005-11-09
SwTextNode* pTextNd( pNd->GetTextNode() );
SwNumRule* pNumRule( pTextNd->GetNumRule() );
// sw_redlinehide: not sure what this should do, only called from mail-merge bool bIsNodeNum =
( pNumRule && pTextNd->GetNum() &&
( pTextNd->HasNumber() || pTextNd->HasBullet() ) &&
pTextNd->IsCountedInList() &&
!pTextNd->IsListRestart() ); if (bIsNodeNum)
{ int nListLevel = pTextNd->GetActualListLevel();
if (nListLevel < 0)
nListLevel = 0;
if (nListLevel >= MAXLEVEL)
nListLevel = MAXLEVEL - 1;
bIsNodeNum = pTextNd->GetNum()->GetNumber() ==
pNumRule->Get( o3tl::narrowing<sal_uInt16>(nListLevel) ).GetStart();
} if (bIsNodeNum)
{ // now set the start value as attribute
SwPosition aCurrentNode(*pNd);
GetDoc()->SetNumRuleStart( aCurrentNode );
}
}
} break; case SwNodeType::Section: // skip hidden sections - ignore protection! if(static_cast<SwSectionNode*>(pNd)->GetSection().IsHidden() )
nCurrNd = pNd->EndOfSectionIndex(); break; default: break;
}
// Interface for TextInputData - (for text input of japanese/chinese characters) void SwEditShell::CreateExtTextInput(LanguageType eInputLanguage)
{
SwExtTextInput* pRet = GetDoc()->CreateExtTextInput( *GetCursor() );
pRet->SetLanguage(eInputLanguage);
pRet->SetOverwriteCursor( SwCursorShell::IsOverwriteCursor() );
}
OUString SwEditShell::DeleteExtTextInput( bool bInsText )
{ const SwPosition& rPos = *GetCursor()->GetPoint();
SwExtTextInput* pDel = GetDoc()->GetExtTextInput( rPos.GetNode(),
rPos.GetContentIndex() ); if( !pDel )
{ //JP 25.10.2001: under UNIX the cursor is moved before the Input- // Engine event comes in. So take any - normally there // exist only one at the time. -- Task 92016
pDel = GetDoc()->GetExtTextInput();
}
OUString sRet; if( pDel )
{
OUString sTmp;
SwUnoCursorHelper::GetTextFromPam(*pDel, sTmp);
sRet = sTmp;
CurrShell aCurr( this );
StartAllAction();
pDel->SetInsText( bInsText );
SetOverwriteCursor( pDel->IsOverwriteCursor() ); const SwPosition aPos( *pDel->GetPoint() );
GetDoc()->DeleteExtTextInput( pDel );
// In this case, the "replace" function did not set the cursor // to the original position. Therefore we have to do this manually. if ( ! bInsText && IsOverwriteCursor() )
*GetCursor()->GetPoint() = aPos;
// ugly but works
ShowCursor(); const sal_Int32 nDiff = nNewCursorPos - rPos.GetContentIndex(); if( nDiff != 0)
{ bool bLeft = nDiff < 0;
sal_Int32 nMaxGuard = std::abs(nDiff); while (true)
{ auto nOldPos = pCurrentCursor->GetPoint()->GetContentIndex(); if (bLeft)
Left(1, SwCursorSkipMode::Chars); else
Right(1, SwCursorSkipMode::Chars); auto nNewPos = pCurrentCursor->GetPoint()->GetContentIndex();
// expected success if (nNewPos == nNewCursorPos) break;
if (nNewPos == nOldPos)
{ // if there was no movement, we have failed for some reason
SAL_WARN("sw.core", "IM cursor move failed"); break;
}
if (--nMaxGuard == 0)
{ // if it takes more cursor moves than there are utf-16 chars to move past // something has probably gone wrong
SAL_WARN("sw.core", "IM abandoning cursor positioning"); break;
}
}
}
SetOverwriteCursor( rData.IsCursorOverwrite() );
EndAllAction();
if( !rData.IsCursorVisible() ) // must be called after the EndAction
HideCursor();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.