Files
libreoffice/sw/source/core/edit/edsect.cxx

433 lines
14 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patches contributed by Oliver-Rainer Wittmann sw34bf06: #i117783# - Writer's implementation of XPagePrintable - apply print settings to new printing routines http://svn.apache.org/viewvc?view=revision&revision=1172115 sw34bf06: #o12311627# use <rtl_random> methods to create unique ids for list styles and list ids http://svn.apache.org/viewvc?view=revision&revision=1172112 sw34bf06 #i114725#,#i115828# - method <SwDoc::ClearDoc()> - clear list structures completely http://svn.apache.org/viewvc?view=revision&revision=1172122 i#118572 - remove ui string and help content regarding usage of Java Mail in Writer's Mail Merge as Java Mail is not used. http://svn.apache.org/viewvc?view=revision&revision=1197035 Patches contributed by Mathias Bauer cws mba34issues01: #i117718#: provide filter name in case storage of medium does not allow to detect one http://svn.apache.org/viewvc?view=revision&revision=1172350 cws mba34issues01: #i117721#: directly provide parameters retrieved from SfxMedium http://svn.apache.org/viewvc?view=revision&revision=1172353 gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 cws mba34issues01: #i117723#: convert assertion into trace http://svn.apache.org/viewvc?view=revision&revision=1172355 cws mba34issues01: #i117699#: keep layout alive until swdoc dies http://svn.apache.org/viewvc?view=revision&revision=1172362 cws mba34issues01: #i117943#: missing color attributes in RTF clipboard http://svn.apache.org/viewvc?view=revision&revision=1172363 Patch contributed by Henning Brinkmann imported patch i#103878 http://svn.apache.org/viewvc?view=revision&revision=1172109 Patches contributed by Michael Stahl sw34bf06: #i117955#: WW8 export: disable storing of section breaks in endnotes http://svn.apache.org/viewvc?view=revision&revision=1172119 Patch contributed by imacat Fixed the Asian language work count. http://svn.apache.org/viewvc?view=revision&revision=1241345 Patch contributed by Pedro Giffuni i#20878 - Add comment with BZ issue for reference. http://svn.apache.org/viewvc?view=revision&revision=1244517 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 add writerperfect dependency.
2011-03-31 10:05:04 +02:00
/*
* 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 .
*/
2000-09-18 23:08:29 +00:00
#include <editsh.hxx>
#include <doc.hxx>
#include <IDocumentUndoRedo.hxx>
2000-09-18 23:08:29 +00:00
#include <pam.hxx>
#include <docary.hxx>
#include <swundo.hxx>
2000-09-18 23:08:29 +00:00
#include <section.hxx>
#include <edimp.hxx>
#include <sectfrm.hxx>
#include <cntfrm.hxx>
#include <tabfrm.hxx>
#include <rootfrm.hxx>
2000-09-18 23:08:29 +00:00
SwSection const*
SwEditShell::InsertSection(
SwSectionData & rNewData, SfxItemSet const*const pAttr)
2000-09-18 23:08:29 +00:00
{
const SwSection* pRet = 0;
if( !IsTableMode() )
{
StartAllAction();
GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_INSSECTION, NULL );
2000-09-18 23:08:29 +00:00
FOREACHPAM_START(GetCrsr())
SwSection const*const pNew =
GetDoc()->InsertSwSection( *PCURCRSR, rNewData, 0, pAttr );
2000-09-18 23:08:29 +00:00
if( !pRet )
pRet = pNew;
FOREACHPAM_END()
GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_INSSECTION, NULL );
2000-09-18 23:08:29 +00:00
EndAllAction();
}
return pRet;
}
sal_Bool SwEditShell::IsInsRegionAvailable() const
2000-09-18 23:08:29 +00:00
{
CWS-TOOLING: integrate CWS bjm02 2009-08-12 Bjoern Michaelsen #i101879# moved officeversion from envelope body to requestbody 2009-08-11 Bjoern Michaelsen #i103732# reverting changeset f3f527950572 2009-08-10 Bjoern Michaelsen cws bjm02: merging local minibranches 2009-08-10 Bjoern Michaelsen #i104128# remove additional duplication in svx headers, remove license header merge conflicts in svx headers 2009-08-10 Bjoern Michaelsen #i100484# fixed buildbreaker on win32 2009-08-10 Bjoern Michaelsen #i104128# remove duplication in svx headers 2009-08-04 Bjoern Michaelsen #i103913# fixed bookmark updating when moving numbered para 2009-08-03 Bjoern Michaelsen #i101879# include officeversion/productname in soaprequest 2009-07-31 Bjoern Michaelsen #i84926# Selecting all in blockmode automatically falls back to std mode 2009-07-31 Bjoern Michaelsen #i100484# operation on 'pCmpLine' may be undefined, thanks cmc 2009-07-29 Bjoern Michaelsen #i103059# fixing crash on empty enumeration 2009-07-29 Bjoern Michaelsen #i98659# fixing typo in usagetracking option tabpage 2009-07-29 Bjoern Michaelsen #i103732# not triggering loading of oooimprovement dll if usage tracking is disabled 2009-07-29 Bjoern Michaelsen #i103036# stlunosequence can be use simple array-pointers as iterators, fixing used type in xmloff 2009-07-29 Bjoern Michaelsen #i103036# stlunosequence can be use simple array-pointers as iterators 2009-07-29 Bjoern Michaelsen #i103182# completely removing unused functions in extensions/oooimprovement 2009-07-28 Bjoern Michaelsen cws bjm02: merged changes from master up to milestone DEV300_m53 2009-06-29 Bjoern Michaelsen #i103182# commenting out getFailedAttempts(..) for future use 2009-06-29 Bjoern Michaelsen #i103183# removed unused function sw::mark::CrossRefBookmark::IsLegalName(..) 2009-06-29 Bjoern Michaelsen #i103182# removing unused functions in extensions/oooimprovement 2009-06-24 Bjoern Michaelsen #i103059# not using enumeration for getByName/getByIndex 2009-06-24 Bjoern Michaelsen #i103059# not using enumeration for hasByName/GetCount/hasElements for performance reasons 2009-06-24 Bjoern Michaelsen #i103036# stlunosequence can be use simple array-pointers as iterators 2009-08-27 releng CWS-TOOLING: integrate CWS hr65 2009-08-26 Jens-Heiner Rechtien #i104521#: implement 'setcurrent'; document --hg option to 'create' 2009-08-26 Jens-Heiner Rechtien #i104521#: SOAP method setSCMName() doesn't return a value 2009-08-26 Jens-Heiner Rechtien #i104521#: implement [set|get]_scm() 2009-08-26 Jens-Heiner Rechtien #i104521#: implement --hg switch to 'cws create' 2009-08-27 vg CWS-TOOLING: integrate CWS hr64_DEV300 2009-07-21 13:24:57 +0200 hr r274189 : #i99576#: re-enable optimization for tabcont.cxx 2009-07-21 13:17:18 +0200 hr r274188 : #i99592: disable -xspace optimization for Solaris x86 and SunStudio 12, due to some mis-optimzation in sc and elsewhere. SunStudio 12 update 1 is OK, but needs a few unrelated changes which will be implemented in DEV300 code line 2009-08-27 releng CWS-TOOLING: integrate CWS sw32bf02 2009-08-25 15:52:04 +0200 hde r275366 : reactived testcases hit by issue 102752 2009-08-21 13:52:17 +0200 od r275245 : #i102921# delete files whose deletion has been forgotten in cws impress172 2009-08-21 11:20:47 +0200 od r275225 : CWS-TOOLING: rebase CWS sw32bf02 to trunk@275001 (milestone: DEV300:m55) 2009-08-20 16:21:30 +0200 od r275191 : #i92511# method <lcl_MoveAllLowerObjs(..)> - invalidation of cache for object rectangle inclusive spaces is needed. 2009-08-20 15:50:40 +0200 od r275188 : #i96726# method <SwPagePreView::DocSzChgd(..)> - trigger recalculation of page preview layout even if the count of pages is not changing 2009-08-20 12:37:32 +0200 od r275172 : #i100466# correction for showing and hiding redlines 2009-08-18 13:25:18 +0200 od r275100 : #i103817# method <XMLTextImportHelper::SetStyleAndAttrs(..) - assure that a heading applies the outline style, if no other list style is applied. 2009-08-18 13:21:38 +0200 od r275098 : #i103817# allow the outline style - list style for outline numbering - to be set directly at the paragraph 2009-08-17 14:13:02 +0200 od r275052 : #i103684# add missing documentation for new optional OutlineLevel attribute introduced in OOo 3.1 2009-08-17 14:00:25 +0200 od r275049 : #i100481# method <XMLTextFrameContext_Impl::CreateChildContext(..)># - correct condition for handling embedded documents and embedded math objects 2009-08-12 14:11:34 +0200 od r274891 : #i97379# assure that columns are not applied to fly frames, which represent graphics or embedded objects 2009-08-12 12:51:43 +0200 od r274889 : #i101870# method <SwTxtNode::_MakeNewTxtNode(..)> - perform action on different paragraph styles before applying new paragraph style 2009-08-12 12:24:44 +0200 od r274888 : #i101092# method <ViewShell::Paint(..)> - encapsulate paint of document background and document into pre and post drawing layer paint calls 2009-08-12 11:38:48 +0200 od r274886 : #i98766# minor adjustment in order to be warning free under Mac port builds 2009-08-12 11:33:54 +0200 od r274885 : #i99267# method <SwTabFrm::MakeAll()> - reset <bSplit> after forward move to assure that follows can be joined, if further space is available. 2009-08-12 11:11:49 +0200 od r274882 : #i98766# method <ViewShell::SmoothScroll(..) - disable smooth scroll for Mac port builds 2009-08-10 12:17:58 +0200 od r274801 : CWS-TOOLING: rebase CWS sw32bf02 to trunk@274622 (milestone: DEV300:m54) 2009-07-21 16:56:45 +0200 od r274206 : #i103685# method <SwTxtFormatter::NewTabPortion(..)> - adjust condition to apply automatic tab stop at left margin correctly in case that tab stops are not relative to indent 2009-07-10 11:53:53 +0200 od r273883 : #i102752 method <SwDrawContact::Modify(..)> - assure that a ShapePropertyChangeNotifier exists 2009-07-07 12:01:58 +0200 mst r273788 : #i103304# apply patch by dtardon to fix bogus conditional 2009-07-07 09:01:13 +0200 od r273767 : CWS-TOOLING: rebase CWS sw32bf02 to trunk@273468 (milestone: DEV300:m51) 2009-08-27 vg CWS-TOOLING: integrate CWS native264_DEV300 2009-08-13 11:58:58 +0200 is r274928 : #i104200# update to jre6u16 2009-08-27 vg CWS-TOOLING: integrate CWS automationdev300m54tables 2009-08-14 13:01:05 +0200 wg r274976 : i104224 2009-08-14 13:00:28 +0200 wg r274975 : i104224 2009-08-14 12:12:34 +0200 wg r274974 : i104222 2009-08-13 14:28:13 +0200 wg r274944 : i104205 2009-08-13 14:27:40 +0200 wg r274943 : i104205 2009-08-13 14:26:36 +0200 wg r274942 : i104205
2009-08-27 15:54:55 +00:00
if( IsTableMode() )
return sal_False;
CWS-TOOLING: integrate CWS bjm02 2009-08-12 Bjoern Michaelsen #i101879# moved officeversion from envelope body to requestbody 2009-08-11 Bjoern Michaelsen #i103732# reverting changeset f3f527950572 2009-08-10 Bjoern Michaelsen cws bjm02: merging local minibranches 2009-08-10 Bjoern Michaelsen #i104128# remove additional duplication in svx headers, remove license header merge conflicts in svx headers 2009-08-10 Bjoern Michaelsen #i100484# fixed buildbreaker on win32 2009-08-10 Bjoern Michaelsen #i104128# remove duplication in svx headers 2009-08-04 Bjoern Michaelsen #i103913# fixed bookmark updating when moving numbered para 2009-08-03 Bjoern Michaelsen #i101879# include officeversion/productname in soaprequest 2009-07-31 Bjoern Michaelsen #i84926# Selecting all in blockmode automatically falls back to std mode 2009-07-31 Bjoern Michaelsen #i100484# operation on 'pCmpLine' may be undefined, thanks cmc 2009-07-29 Bjoern Michaelsen #i103059# fixing crash on empty enumeration 2009-07-29 Bjoern Michaelsen #i98659# fixing typo in usagetracking option tabpage 2009-07-29 Bjoern Michaelsen #i103732# not triggering loading of oooimprovement dll if usage tracking is disabled 2009-07-29 Bjoern Michaelsen #i103036# stlunosequence can be use simple array-pointers as iterators, fixing used type in xmloff 2009-07-29 Bjoern Michaelsen #i103036# stlunosequence can be use simple array-pointers as iterators 2009-07-29 Bjoern Michaelsen #i103182# completely removing unused functions in extensions/oooimprovement 2009-07-28 Bjoern Michaelsen cws bjm02: merged changes from master up to milestone DEV300_m53 2009-06-29 Bjoern Michaelsen #i103182# commenting out getFailedAttempts(..) for future use 2009-06-29 Bjoern Michaelsen #i103183# removed unused function sw::mark::CrossRefBookmark::IsLegalName(..) 2009-06-29 Bjoern Michaelsen #i103182# removing unused functions in extensions/oooimprovement 2009-06-24 Bjoern Michaelsen #i103059# not using enumeration for getByName/getByIndex 2009-06-24 Bjoern Michaelsen #i103059# not using enumeration for hasByName/GetCount/hasElements for performance reasons 2009-06-24 Bjoern Michaelsen #i103036# stlunosequence can be use simple array-pointers as iterators 2009-08-27 releng CWS-TOOLING: integrate CWS hr65 2009-08-26 Jens-Heiner Rechtien #i104521#: implement 'setcurrent'; document --hg option to 'create' 2009-08-26 Jens-Heiner Rechtien #i104521#: SOAP method setSCMName() doesn't return a value 2009-08-26 Jens-Heiner Rechtien #i104521#: implement [set|get]_scm() 2009-08-26 Jens-Heiner Rechtien #i104521#: implement --hg switch to 'cws create' 2009-08-27 vg CWS-TOOLING: integrate CWS hr64_DEV300 2009-07-21 13:24:57 +0200 hr r274189 : #i99576#: re-enable optimization for tabcont.cxx 2009-07-21 13:17:18 +0200 hr r274188 : #i99592: disable -xspace optimization for Solaris x86 and SunStudio 12, due to some mis-optimzation in sc and elsewhere. SunStudio 12 update 1 is OK, but needs a few unrelated changes which will be implemented in DEV300 code line 2009-08-27 releng CWS-TOOLING: integrate CWS sw32bf02 2009-08-25 15:52:04 +0200 hde r275366 : reactived testcases hit by issue 102752 2009-08-21 13:52:17 +0200 od r275245 : #i102921# delete files whose deletion has been forgotten in cws impress172 2009-08-21 11:20:47 +0200 od r275225 : CWS-TOOLING: rebase CWS sw32bf02 to trunk@275001 (milestone: DEV300:m55) 2009-08-20 16:21:30 +0200 od r275191 : #i92511# method <lcl_MoveAllLowerObjs(..)> - invalidation of cache for object rectangle inclusive spaces is needed. 2009-08-20 15:50:40 +0200 od r275188 : #i96726# method <SwPagePreView::DocSzChgd(..)> - trigger recalculation of page preview layout even if the count of pages is not changing 2009-08-20 12:37:32 +0200 od r275172 : #i100466# correction for showing and hiding redlines 2009-08-18 13:25:18 +0200 od r275100 : #i103817# method <XMLTextImportHelper::SetStyleAndAttrs(..) - assure that a heading applies the outline style, if no other list style is applied. 2009-08-18 13:21:38 +0200 od r275098 : #i103817# allow the outline style - list style for outline numbering - to be set directly at the paragraph 2009-08-17 14:13:02 +0200 od r275052 : #i103684# add missing documentation for new optional OutlineLevel attribute introduced in OOo 3.1 2009-08-17 14:00:25 +0200 od r275049 : #i100481# method <XMLTextFrameContext_Impl::CreateChildContext(..)># - correct condition for handling embedded documents and embedded math objects 2009-08-12 14:11:34 +0200 od r274891 : #i97379# assure that columns are not applied to fly frames, which represent graphics or embedded objects 2009-08-12 12:51:43 +0200 od r274889 : #i101870# method <SwTxtNode::_MakeNewTxtNode(..)> - perform action on different paragraph styles before applying new paragraph style 2009-08-12 12:24:44 +0200 od r274888 : #i101092# method <ViewShell::Paint(..)> - encapsulate paint of document background and document into pre and post drawing layer paint calls 2009-08-12 11:38:48 +0200 od r274886 : #i98766# minor adjustment in order to be warning free under Mac port builds 2009-08-12 11:33:54 +0200 od r274885 : #i99267# method <SwTabFrm::MakeAll()> - reset <bSplit> after forward move to assure that follows can be joined, if further space is available. 2009-08-12 11:11:49 +0200 od r274882 : #i98766# method <ViewShell::SmoothScroll(..) - disable smooth scroll for Mac port builds 2009-08-10 12:17:58 +0200 od r274801 : CWS-TOOLING: rebase CWS sw32bf02 to trunk@274622 (milestone: DEV300:m54) 2009-07-21 16:56:45 +0200 od r274206 : #i103685# method <SwTxtFormatter::NewTabPortion(..)> - adjust condition to apply automatic tab stop at left margin correctly in case that tab stops are not relative to indent 2009-07-10 11:53:53 +0200 od r273883 : #i102752 method <SwDrawContact::Modify(..)> - assure that a ShapePropertyChangeNotifier exists 2009-07-07 12:01:58 +0200 mst r273788 : #i103304# apply patch by dtardon to fix bogus conditional 2009-07-07 09:01:13 +0200 od r273767 : CWS-TOOLING: rebase CWS sw32bf02 to trunk@273468 (milestone: DEV300:m51) 2009-08-27 vg CWS-TOOLING: integrate CWS native264_DEV300 2009-08-13 11:58:58 +0200 is r274928 : #i104200# update to jre6u16 2009-08-27 vg CWS-TOOLING: integrate CWS automationdev300m54tables 2009-08-14 13:01:05 +0200 wg r274976 : i104224 2009-08-14 13:00:28 +0200 wg r274975 : i104224 2009-08-14 12:12:34 +0200 wg r274974 : i104222 2009-08-13 14:28:13 +0200 wg r274944 : i104205 2009-08-13 14:27:40 +0200 wg r274943 : i104205 2009-08-13 14:26:36 +0200 wg r274942 : i104205
2009-08-27 15:54:55 +00:00
SwPaM* pCrsr = GetCrsr();
if( pCrsr->GetNext() != pCrsr )
return sal_False;
2000-09-18 23:08:29 +00:00
if( pCrsr->HasMark() )
return 0 != GetDoc()->IsInsRegionAvailable( *pCrsr );
return sal_True;
2000-09-18 23:08:29 +00:00
}
const SwSection* SwEditShell::GetCurrSection() const
{
if( IsTableMode() )
return 0;
return GetDoc()->GetCurrSection( *GetCrsr()->GetPoint() );
}
/** Deliver the responsible area of the columns.
*
* In footnotes it may not be the area within the footnote.
*/
const SwSection* SwEditShell::GetAnySection( sal_Bool bOutOfTab, const Point* pPt ) const
2000-09-18 23:08:29 +00:00
{
SwFrm *pFrm;
if ( pPt )
{
SwPosition aPos( *GetCrsr()->GetPoint() );
Point aPt( *pPt );
GetLayout()->GetCrsrOfst( &aPos, aPt );
SwCntntNode *pNd = aPos.nNode.GetNode().GetCntntNode();
pFrm = pNd->getLayoutFrm( GetLayout(), pPt );
}
else
pFrm = GetCurrFrm( sal_False );
2000-09-18 23:08:29 +00:00
if( bOutOfTab && pFrm )
pFrm = pFrm->FindTabFrm();
if( pFrm && pFrm->IsInSct() )
{
SwSectionFrm* pSect = pFrm->FindSctFrm();
OSL_ENSURE( pSect, "GetAnySection: Where's my Sect?" );
2000-09-18 23:08:29 +00:00
if( pSect->IsInFtn() && pSect->GetUpper()->IsInSct() )
{
pSect = pSect->GetUpper()->FindSctFrm();
OSL_ENSURE( pSect, "GetAnySection: Where's my SectFrm?" );
2000-09-18 23:08:29 +00:00
}
return pSect->GetSection();
}
return NULL;
}
sal_uInt16 SwEditShell::GetSectionFmtCount() const
2000-09-18 23:08:29 +00:00
{
return GetDoc()->GetSections().size();
2000-09-18 23:08:29 +00:00
}
sal_Bool SwEditShell::IsAnySectionInDoc( sal_Bool bChkReadOnly, sal_Bool bChkHidden, sal_Bool bChkTOX ) const
2000-09-18 23:08:29 +00:00
{
const SwSectionFmts& rFmts = GetDoc()->GetSections();
sal_uInt16 nCnt = rFmts.size();
sal_uInt16 n;
for( n = 0; n < nCnt; ++n )
2000-09-18 23:08:29 +00:00
{
SectionType eTmpType;
const SwSectionFmt* pFmt = rFmts[ n ];
if( pFmt->IsInNodesArr() &&
(bChkTOX ||
2010-11-04 13:05:15 +01:00
( (eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
&& TOX_HEADER_SECTION != eTmpType ) ) )
2000-09-18 23:08:29 +00:00
{
const SwSection& rSect = *rFmts[ n ]->GetSection();
if( (!bChkReadOnly && !bChkHidden ) ||
(bChkReadOnly && rSect.IsProtectFlag() ) ||
(bChkHidden && rSect.IsHiddenFlag() ) )
break;
}
}
return n != nCnt;
}
sal_uInt16 SwEditShell::GetSectionFmtPos( const SwSectionFmt& rFmt ) const
2000-09-18 23:08:29 +00:00
{
SwSectionFmt* pFmt = (SwSectionFmt*)&rFmt;
return GetDoc()->GetSections().GetPos( pFmt );
}
const SwSectionFmt& SwEditShell::GetSectionFmt( sal_uInt16 nFmt ) const
2000-09-18 23:08:29 +00:00
{
return *GetDoc()->GetSections()[ nFmt ];
}
void SwEditShell::DelSectionFmt( sal_uInt16 nFmt )
2000-09-18 23:08:29 +00:00
{
StartAllAction();
GetDoc()->DelSectionFmt( GetDoc()->GetSections()[ nFmt ] );
// Call the AttrChangeNotify on the UI page.
2000-09-18 23:08:29 +00:00
CallChgLnk();
EndAllAction();
}
void SwEditShell::UpdateSection(sal_uInt16 const nSect,
SwSectionData & rNewData, SfxItemSet const*const pAttr)
2000-09-18 23:08:29 +00:00
{
StartAllAction();
GetDoc()->UpdateSection( nSect, rNewData, pAttr );
// Call the AttrChangeNotify on the UI page.
2000-09-18 23:08:29 +00:00
CallChgLnk();
EndAllAction();
}
OUString SwEditShell::GetUniqueSectionName( const OUString* pChkStr ) const
2000-09-18 23:08:29 +00:00
{
return GetDoc()->GetUniqueSectionName( pChkStr );
}
void SwEditShell::SetSectionAttr( const SfxItemSet& rSet,
SwSectionFmt* pSectFmt )
{
if( pSectFmt )
_SetSectionAttr( *pSectFmt, rSet );
else
{
// for all section in the selection
FOREACHPAM_START(GetCrsr())
2000-09-18 23:08:29 +00:00
const SwPosition* pStt = PCURCRSR->Start(),
* pEnd = PCURCRSR->End();
const SwSectionNode* pSttSectNd = pStt->nNode.GetNode().FindSectionNode(),
* pEndSectNd = pEnd->nNode.GetNode().FindSectionNode();
if( pSttSectNd || pEndSectNd )
{
if( pSttSectNd )
_SetSectionAttr( *pSttSectNd->GetSection().GetFmt(),
rSet );
if( pEndSectNd && pSttSectNd != pEndSectNd )
_SetSectionAttr( *pEndSectNd->GetSection().GetFmt(),
rSet );
if( pSttSectNd && pEndSectNd )
{
SwNodeIndex aSIdx( pStt->nNode );
SwNodeIndex aEIdx( pEnd->nNode );
if( pSttSectNd->EndOfSectionIndex() <
pEndSectNd->GetIndex() )
{
aSIdx = pSttSectNd->EndOfSectionIndex() + 1;
aEIdx = *pEndSectNd;
}
while( aSIdx < aEIdx )
{
if( 0 != (pSttSectNd = aSIdx.GetNode().GetSectionNode())
|| ( aSIdx.GetNode().IsEndNode() &&
0 != ( pSttSectNd = aSIdx.GetNode().
StartOfSectionNode()->GetSectionNode())) )
2000-09-18 23:08:29 +00:00
_SetSectionAttr( *pSttSectNd->GetSection().GetFmt(),
rSet );
++aSIdx;
2000-09-18 23:08:29 +00:00
}
}
}
FOREACHPAM_END()
}
}
void SwEditShell::_SetSectionAttr( SwSectionFmt& rSectFmt,
const SfxItemSet& rSet )
{
StartAllAction();
if(SFX_ITEM_SET == rSet.GetItemState(RES_CNTNT, sal_False))
2000-09-18 23:08:29 +00:00
{
SfxItemSet aSet(rSet);
aSet.ClearItem(RES_CNTNT);
GetDoc()->SetAttr( aSet, rSectFmt );
}
else
GetDoc()->SetAttr( rSet, rSectFmt );
// Call the AttrChangeNotify on the UI page.
2000-09-18 23:08:29 +00:00
CallChgLnk();
EndAllAction();
}
/** Search inside the cursor selection for full selected sections.
*
* @return If any part of section in the selection return 0, if more than one return the count.
*/
sal_uInt16 SwEditShell::GetFullSelectedSectionCount() const
2000-09-18 23:08:29 +00:00
{
sal_uInt16 nRet = 0;
FOREACHPAM_START(GetCrsr())
2000-09-18 23:08:29 +00:00
const SwPosition* pStt = PCURCRSR->Start(),
* pEnd = PCURCRSR->End();
const SwCntntNode* pCNd;
// check the selection, if Start at Node begin and End at Node end
if( pStt->nContent.GetIndex() ||
( 0 == ( pCNd = pEnd->nNode.GetNode().GetCntntNode() )) ||
pCNd->Len() != pEnd->nContent.GetIndex() )
{
nRet = 0;
break;
}
// !!!
2000-09-18 23:08:29 +00:00
// what about table at start or end ?
// There is no selection possible!
// What about only a table inside the section ?
// There is only a table selection possible!
SwNodeIndex aSIdx( pStt->nNode, -1 ), aEIdx( pEnd->nNode, +1 );
if( !aSIdx.GetNode().IsSectionNode() ||
!aEIdx.GetNode().IsEndNode() ||
!aEIdx.GetNode().StartOfSectionNode()->IsSectionNode() )
2000-09-18 23:08:29 +00:00
{
nRet = 0;
break;
}
++nRet;
if( &aSIdx.GetNode() != aEIdx.GetNode().StartOfSectionNode() )
2000-09-18 23:08:29 +00:00
++nRet;
FOREACHPAM_END()
return nRet;
}
/** Find the suitable node for a special insert (alt-enter).
*
* This should enable inserting text before/after sections and tables.
*
* A node is found if:
* 1) the innermost table/section is not in a write-protected area
* 2) pCurrentPos is at or just before an end node
* (or at or just after a start node)
* 3) there are only start/end nodes between pCurrentPos and the innermost
* table/section
*
* If a suitable node is found, an SwNode* is returned; else it is NULL.
*/
static const SwNode* lcl_SpecialInsertNode(const SwPosition* pCurrentPos)
2000-09-18 23:08:29 +00:00
{
const SwNode* pReturn = NULL;
// the current position
OSL_ENSURE( pCurrentPos != NULL, "Strange, we have no position!" );
const SwNode& rCurrentNode = pCurrentPos->nNode.GetNode();
// find innermost section or table. At the end of this scope,
// pInntermostNode contain the section/table before/after which we should
// insert our empty paragraph, or it will be NULL if none is found.
const SwNode* pInnermostNode = NULL;
2000-09-18 23:08:29 +00:00
{
const SwNode* pTableNode = rCurrentNode.FindTableNode();
const SwNode* pSectionNode = rCurrentNode.FindSectionNode();
// find the table/section which is close
if( pTableNode == NULL )
pInnermostNode = pSectionNode;
else if ( pSectionNode == NULL )
pInnermostNode = pTableNode;
else
2000-09-18 23:08:29 +00:00
{
// compare and choose the larger one
pInnermostNode =
( pSectionNode->GetIndex() > pTableNode->GetIndex() )
? pSectionNode : pTableNode;
}
}
2000-09-18 23:08:29 +00:00
// The previous version had a check to skip empty read-only sections. Those
// shouldn't occur, so we only need to check whether our pInnermostNode is
// inside a protected area.
2000-09-18 23:08:29 +00:00
// Now, pInnermostNode is NULL or the innermost section or table node.
if( (pInnermostNode != NULL) && !pInnermostNode->IsProtect() )
{
OSL_ENSURE( pInnermostNode->IsTableNode() ||
pInnermostNode->IsSectionNode(), "wrong node found" );
OSL_ENSURE( ( pInnermostNode->GetIndex() <= rCurrentNode.GetIndex() )&&
( pInnermostNode->EndOfSectionNode()->GetIndex() >=
rCurrentNode.GetIndex() ), "wrong node found" );
// we now need to find the possible start/end positions
// we found a start if
// - we're at or just before a start node
// - there are only start nodes between the current and pInnermostNode
SwNodeIndex aBegin( pCurrentPos->nNode );
if( rCurrentNode.IsCntntNode() &&
(pCurrentPos->nContent.GetIndex() == 0))
aBegin--;
while( (aBegin != pInnermostNode->GetIndex()) &&
aBegin.GetNode().IsStartNode() )
aBegin--;
bool bStart = ( aBegin == pInnermostNode->GetIndex() );
// we found an end if
// - we're at or just before an end node
// - there are only end nodes between the current node and
// pInnermostNode's end node
SwNodeIndex aEnd( pCurrentPos->nNode );
if( rCurrentNode.IsCntntNode() &&
( pCurrentPos->nContent.GetIndex() ==
rCurrentNode.GetCntntNode()->Len() ) )
++aEnd;
while( (aEnd != pInnermostNode->EndOfSectionNode()->GetIndex()) &&
aEnd.GetNode().IsEndNode() )
++aEnd;
bool bEnd = ( aEnd == pInnermostNode->EndOfSectionNode()->GetIndex() );
// evalutate result: if both start + end, end is preferred
if( bEnd )
pReturn = pInnermostNode->EndOfSectionNode();
else if ( bStart )
pReturn = pInnermostNode;
2000-09-18 23:08:29 +00:00
}
OSL_ENSURE( ( pReturn == NULL ) || pReturn->IsStartNode() ||
pReturn->IsEndNode(),
"SpecialInsertNode failed" );
return pReturn;
2000-09-18 23:08:29 +00:00
}
/** a node can be special-inserted (alt-Enter) whenever lcl_SpecialInsertNode
finds a suitable position
*/
bool SwEditShell::CanSpecialInsert() const
{
return NULL != lcl_SpecialInsertNode( GetCrsr()->GetPoint() );
}
/** check whether a node can be special-inserted (alt-Enter), and do so. Return
whether insertion was possible.
*/
bool SwEditShell::DoSpecialInsert()
2000-09-18 23:08:29 +00:00
{
bool bRet = false;
// get current node
SwPosition* pCursorPos = GetCrsr()->GetPoint();
const SwNode* pInsertNode = lcl_SpecialInsertNode( pCursorPos );
if( pInsertNode != NULL )
2000-09-18 23:08:29 +00:00
{
StartAllAction();
// adjust insert position to insert before start nodes and after end
// nodes
SwNodeIndex aInsertIndex( *pInsertNode,
pInsertNode->IsStartNode() ? -1 : 0 );
SwPosition aInsertPos( aInsertIndex );
2000-09-18 23:08:29 +00:00
// insert a new text node, and set the cursor
bRet = GetDoc()->AppendTxtNode( aInsertPos );
*pCursorPos = aInsertPos;
2000-09-18 23:08:29 +00:00
// call AttrChangeNotify for the UI
2000-09-18 23:08:29 +00:00
CallChgLnk();
2000-09-18 23:08:29 +00:00
EndAllAction();
}
return bRet;
}
2000-09-18 23:08:29 +00:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */