1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <com/sun/star/container/XChild.hpp>
22 #include <com/sun/star/embed/XVisualObject.hpp>
23 #include <com/sun/star/embed/EmbedMisc.hpp>
24 #include <com/sun/star/embed/EmbedStates.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
27 #include <com/sun/star/chart2/XChartDocument.hpp>
28 #include <com/sun/star/util/XModifiable.hpp>
30 #include <svx/dialogs.hrc>
33 #include <hintids.hxx>
34 #include <svx/svdview.hxx>
35 #include <sot/factory.hxx>
36 #include <svl/itemiter.hxx>
37 #include <tools/bigint.hxx>
38 #include <sot/storage.hxx>
39 #include <svtools/insdlg.hxx>
40 #include <sfx2/frmdescr.hxx>
41 #include <sfx2/ipclient.hxx>
42 #include <svtools/ehdl.hxx>
43 #include <svtools/soerr.hxx>
44 #include <tools/cachestr.hxx>
45 #include <unotools/moduleoptions.hxx>
46 #include <editeng/sizeitem.hxx>
47 #include <editeng/formatbreakitem.hxx>
48 #include <editeng/svxacorr.hxx>
49 #include <editeng/ulspitem.hxx>
50 #include <vcl/graph.hxx>
51 #include <vcl/msgbox.hxx>
52 #include <sfx2/printer.hxx>
53 #include <unotools/charclass.hxx>
54 #include <comphelper/storagehelper.hxx>
55 #include <svx/svxdlg.hxx>
56 #include <svx/extrusionbar.hxx>
57 #include <svx/fontworkbar.hxx>
60 #include <fmthdft.hxx>
61 #include <fmtpdsc.hxx>
64 #include <swmodule.hxx>
69 #include <cfgitems.hxx>
70 #include <pagedesc.hxx>
72 #include <shellio.hxx>
74 #include <swundo.hxx> // for Undo-Ids
76 #include <poolfmt.hxx>
80 #include <swtable.hxx>
81 #include <caption.hxx>
83 #include <swdtflvr.hxx>
84 #include <crsskip.hxx>
87 #include <SwStyleNameMapper.hxx>
88 #include <sfx2/request.hxx>
91 #include <editeng/acorrcfg.hxx>
93 #include <sfx2/bindings.hxx>
94 #include <svx/dialmgr.hxx>
97 #include <SwRewriter.hxx>
98 #include <comcore.hrc>
101 #include <toolkit/helper/vclunohelper.hxx>
102 #include <sfx2/viewfrm.hxx>
104 #include "PostItMgr.hxx"
105 #include <sfx2/msgpool.hxx>
107 using namespace sw::mark
;
108 using namespace com::sun::star
;
110 #define COMMON_INI_LIST \
111 fnDrag(&SwWrtShell::BeginDrag),\
112 fnSetCrsr(&SwWrtShell::SetCrsr),\
113 fnEndDrag(&SwWrtShell::EndDrag),\
114 fnKillSel(&SwWrtShell::Ignore),\
119 aNavigationMgr(*this), \
122 #define BITFLD_INI_LIST \
133 mbRetainSelection = sal_False; \
134 bIsInClickToEdit = false;
136 static SvxAutoCorrect
* lcl_IsAutoCorr()
138 SvxAutoCorrect
* pACorr
= SvxAutoCorrCfg::Get().GetAutoCorrect();
139 if( pACorr
&& !pACorr
->IsAutoCorrFlag( CptlSttSntnc
| CptlSttWrd
|
140 AddNonBrkSpace
| ChgOrdinalNumber
|
141 ChgToEnEmDash
| SetINetAttr
| Autocorrect
))
146 void SwWrtShell::NoEdit(bool bHideCrsr
)
152 void SwWrtShell::Edit()
160 sal_Bool
SwWrtShell::IsEndWrd()
162 SwMvContext
aMvContext(this);
163 if(IsEndPara() && !IsSttPara())
171 void SwWrtShell::InsertByWord( const String
& rStr
)
175 sal_Bool bDelim
= GetAppCharClass().isLetterNumeric( rStr
, 0 );
176 xub_StrLen nPos
= 0, nStt
= 0;
177 for( ; nPos
< rStr
.Len(); nPos
++ )
179 sal_Bool bTmpDelim
= GetAppCharClass().isLetterNumeric( rStr
, nPos
);
180 if( bTmpDelim
!= bDelim
)
182 Insert( rStr
.Copy( nStt
, nPos
- nStt
));
187 Insert( rStr
.Copy( nStt
, nPos
- nStt
));
191 void SwWrtShell::Insert( const String
&rStr
)
197 bool bStarted
= false;
198 sal_Bool bHasSel
= HasSelection(),
199 bCallIns
= bIns
/*|| bHasSel*/;
200 bool bDeleted
= false;
202 if( bHasSel
|| ( !bIns
&& SelectHiddenRange() ) )
204 // Only here parenthesizing, because the normal
205 // insert is already in parentheses at Editshell.
209 SwRewriter aRewriter
;
211 aRewriter
.AddRule(UndoArg1
, GetCrsrDescr());
212 aRewriter
.AddRule(UndoArg2
, String(SW_RES(STR_YIELDS
)));
215 aTmpStr
+= String(SW_RES(STR_START_QUOTE
));
217 aTmpStr
+= String(SW_RES(STR_END_QUOTE
));
219 aRewriter
.AddRule(UndoArg3
, rStr
);
222 StartUndo(UNDO_REPLACE
, &aRewriter
);
224 bDeleted
= DelRight() != 0;
228 SwEditShell::Insert2( rStr
, bDeleted
) : SwEditShell::Overwrite( rStr
);
237 // Maximum height limit not possible, because the maximum height
238 // of the current frame can not be obtained.
240 void SwWrtShell::Insert( const String
&rPath
, const String
&rFilter
,
241 const Graphic
&rGrf
, SwFlyFrmAttrMgr
*pFrmMgr
,
250 SwRewriter aRewriter
;
251 aRewriter
.AddRule(UndoArg1
, SW_RES(STR_GRAPHIC
));
253 StartUndo(UNDO_INSERT
, &aRewriter
);
255 if ( HasSelection() )
257 // Inserted graphics in its own paragraph,
258 // if at the end of a non-empty paragraph.
259 //For i120928,avoid to split node
263 bool bSetGrfSize
= true;
264 bool bOwnMgr
= false;
269 pFrmMgr
= new SwFlyFrmAttrMgr( sal_True
, this, FRMMGR_TYPE_GRF
);
272 // GetAttrSet makes an adjustment
273 // While pasting is a SwFrmSize present
274 // because of the DEF-Framesize
275 // These must be removed explicitly for the optimal size.
276 pFrmMgr
->DelAttr(RES_FRM_SIZE
);
280 Size
aSz( pFrmMgr
->GetSize() );
281 if ( !aSz
.Width() || !aSz
.Height() )
283 aSz
.Width() = aSz
.Height() = 567;
284 pFrmMgr
->SetSize( aSz
);
286 else if ( aSz
.Width() != DFLT_WIDTH
&& aSz
.Height() != DFLT_HEIGHT
)
289 pFrmMgr
->SetHeightSizeType(ATT_FIX_SIZE
);
293 // Insert the graphic
294 SwFEShell::Insert(rPath
, rFilter
, &rGrf
, &pFrmMgr
->GetAttrSet());
296 pFrmMgr
->UpdateAttrMgr();
298 if( bSetGrfSize
&& !bRule
)
300 Size aGrfSize
, aBound
= GetGraphicDefaultSize();
301 GetGrfSize( aGrfSize
);
303 // Add the margin attributes to GrfSize,
304 // because these counts at the margin additionaly
305 aGrfSize
.Width() += pFrmMgr
->CalcWidthBorder();
306 aGrfSize
.Height()+= pFrmMgr
->CalcHeightBorder();
308 const BigInt
aTempWidth( aGrfSize
.Width() );
309 const BigInt
aTempHeight( aGrfSize
.Height());
311 // Fit width if necessary, scale down the height proportional thereafter.
312 if( aGrfSize
.Width() > aBound
.Width() )
314 aGrfSize
.Width() = aBound
.Width();
315 aGrfSize
.Height() = ((BigInt
)aBound
.Width()) * aTempHeight
/ aTempWidth
;
317 // Fit hight if necessary, scale down the width proportional thereafter.
318 if( aGrfSize
.Height() > aBound
.Height() )
320 aGrfSize
.Height() = aBound
.Height();
321 aGrfSize
.Width() = ((BigInt
)aBound
.Height()) * aTempWidth
/ aTempHeight
;
323 pFrmMgr
->SetSize( aGrfSize
);
324 pFrmMgr
->UpdateFlyFrm();
333 // Insert an OLE-Objekt into the CORE.
334 // if no object is transfered, then one will be created.
336 void SwWrtShell::InsertObject( const svt::EmbeddedObjectRef
& xRef
, SvGlobalName
*pName
,
337 sal_Bool bActivate
, sal_uInt16 nSlotId
)
346 svt::EmbeddedObjectRef xObj
;
347 uno::Reference
< embed::XStorage
> xStor
= comphelper::OStorageHelper::GetTemporaryStorage();
348 sal_Bool bDoVerb
= sal_True
;
351 comphelper::EmbeddedObjectContainer
aCnt( xStor
);
353 // TODO/LATER: get aspect?
354 xObj
.Assign( aCnt
.CreateEmbeddedObject( pName
->GetByteSequence(), aName
), embed::Aspects::MSOLE_CONTENT
);
358 SvObjectServerList aServerList
;
361 case SID_INSERT_OBJECT
:
363 aServerList
.FillInsertObjects();
364 aServerList
.Remove( SwDocShell::Factory().GetClassId() );
365 // Intentionally no break!
368 // TODO/LATER: recording! Convert properties to items
369 case SID_INSERT_PLUGIN
:
370 case SID_INSERT_FLOATINGFRAME
:
372 SfxSlotPool
* pSlotPool
= SW_MOD()->GetSlotPool();
373 const SfxSlot
* pSlot
= pSlotPool
->GetSlot(nSlotId
);
374 OString
aCmd(".uno:");
375 aCmd
+= pSlot
->GetUnoName();
376 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
377 SfxAbstractInsertObjectDialog
* pDlg
=
378 pFact
->CreateInsertObjectDialog( GetWin(), OStringToOUString( aCmd
, RTL_TEXTENCODING_UTF8
), xStor
, &aServerList
);
382 bDoVerb
= pDlg
->IsCreateNew();
383 OUString aIconMediaType
;
384 uno::Reference
< io::XInputStream
> xIconMetaFile
= pDlg
->GetIconIfIconified( &aIconMediaType
);
385 xObj
.Assign( pDlg
->GetObject(),
386 xIconMetaFile
.is() ? embed::Aspects::MSOLE_ICON
: embed::Aspects::MSOLE_CONTENT
);
387 if ( xIconMetaFile
.is() )
388 xObj
.SetGraphicStream( xIconMetaFile
, aIconMediaType
);
403 if( InsertOleObject( xObj
) && bActivate
&& bDoVerb
)
405 SfxInPlaceClient
* pClient
= GetView().FindIPClient( xObj
.GetObject(), &GetView().GetEditWin() );
408 pClient
= new SwOleClient( &GetView(), &GetView().GetEditWin(), xObj
);
409 SetCheckForOLEInCaption( sal_True
);
412 if ( xObj
.GetViewAspect() == embed::Aspects::MSOLE_ICON
)
414 SwRect aArea
= GetAnyCurRect( RECT_FLY_PRT_EMBEDDED
, 0, xObj
.GetObject() );
415 aArea
.Pos() += GetAnyCurRect( RECT_FLY_EMBEDDED
, 0, xObj
.GetObject() ).Pos();
416 MapMode
aMapMode( MAP_TWIP
);
417 Size aSize
= xObj
.GetSize( &aMapMode
);
418 aArea
.Width( aSize
.Width() );
419 aArea
.Height( aSize
.Height() );
420 RequestObjectResize( aArea
, xObj
.GetObject() );
423 CalcAndSetScale( xObj
);
425 //#50270# We don't need to handle error, this is handled by the
426 //DoVerb in the SfxViewShell
427 pClient
->DoVerb( SVVERB_SHOW
);
429 // TODO/LATER: set document name - should be done in Client
437 InsertOleObject( xRef
);
441 // Insert object into the Core.
442 // From ClipBoard or Insert
444 sal_Bool
SwWrtShell::InsertOleObject( const svt::EmbeddedObjectRef
& xRef
, SwFlyFrmFmt
**pFlyFrmFmt
)
449 StartUndo(UNDO_INSERT
);
451 //Some differences between StarMath and any other objects:
452 //1. Selections should be deleted. For StarMath the Text should be
453 // passed to the Object
454 //2. If the cursor is at the end of an non empty paragraph a paragraph
455 // break should be insertet. StarMath objects are character bound and
456 // no break should be inserted.
457 //3. If an selektion is passed to a StarMath object, this object should
458 // not be activated. sal_False should be returned then.
459 bool bStarMath
= true;
460 sal_Bool bActivate
= sal_True
;
462 // set parent to get correct VisArea(in case of object needing parent printer)
463 uno::Reference
< container::XChild
> xChild( xRef
.GetObject(), uno::UNO_QUERY
);
465 xChild
->setParent( mpDoc
->GetDocShell()->GetModel() );
467 SvGlobalName
aCLSID( xRef
->getClassID() );
468 bStarMath
= ( SotExchange::IsMath( aCLSID
) != 0 );
474 GetSelectedText( aMathData
, GETSELTXT_PARABRK_TO_ONLYCR
);
476 if( aMathData
.Len() && svt::EmbeddedObjectRef::TryRunningState( xRef
.GetObject() ) )
478 uno::Reference
< beans::XPropertySet
> xSet( xRef
->getComponent(), uno::UNO_QUERY
);
483 xSet
->setPropertyValue( OUString("Formula"), uno::makeAny( OUString( aMathData
) ) );
484 bActivate
= sal_False
;
486 catch (const uno::Exception
&)
496 SwFEShell::SplitNode( sal_False
, sal_False
);
500 SwFlyFrmAttrMgr
aFrmMgr( sal_True
, this, FRMMGR_TYPE_OLE
);
501 aFrmMgr
.SetHeightSizeType(ATT_FIX_SIZE
);
504 CalcBoundRect( aBound
, aFrmMgr
.GetAnchor() );
506 //The Size should be suggested by the OLE server
507 MapMode
aMapMode( MAP_TWIP
);
508 Size aSz
= xRef
.GetSize( &aMapMode
);
510 //Object size can be limited
511 if ( aSz
.Width() > aBound
.Width() )
513 //Always limit proportional.
514 aSz
.Height() = aSz
.Height() * aBound
.Width() / aSz
.Width();
515 aSz
.Width() = aBound
.Width();
517 aFrmMgr
.SetSize( aSz
);
518 SwFlyFrmFmt
*pFmt
= SwFEShell::InsertObject( xRef
, &aFrmMgr
.GetAttrSet() );
521 if ( bStarMath
&& mpDoc
->get( IDocumentSettingAccess::MATH_BASELINE_ALIGNMENT
) )
522 AlignFormulaToBaseline( xRef
.GetObject() );
527 if ( SotExchange::IsChart( aCLSID
) )
529 uno::Reference
< embed::XEmbeddedObject
> xEmbeddedObj( xRef
.GetObject(), uno::UNO_QUERY
);
530 if ( xEmbeddedObj
.is() )
532 bool bDisableDataTableDialog
= false;
533 svt::EmbeddedObjectRef::TryRunningState( xEmbeddedObj
);
534 uno::Reference
< beans::XPropertySet
> xProps( xEmbeddedObj
->getComponent(), uno::UNO_QUERY
);
536 ( xProps
->getPropertyValue( OUString( "DisableDataTableDialog" ) ) >>= bDisableDataTableDialog
) &&
537 bDisableDataTableDialog
)
539 xProps
->setPropertyValue( OUString( "DisableDataTableDialog" ),
540 uno::makeAny( sal_False
) );
541 xProps
->setPropertyValue( OUString( "DisableComplexChartTypes" ),
542 uno::makeAny( sal_False
) );
543 uno::Reference
< util::XModifiable
> xModifiable( xProps
, uno::UNO_QUERY
);
544 if ( xModifiable
.is() )
546 xModifiable
->setModified( sal_True
);
553 GetView().AutoCaption(OLE_CAP
, &aCLSID
);
555 SwRewriter aRewriter
;
558 aRewriter
.AddRule(UndoArg1
, SW_RES(STR_MATH_FORMULA
));
559 else if ( SotExchange::IsChart( aCLSID
) )
560 aRewriter
.AddRule(UndoArg1
, SW_RES(STR_CHART
));
562 aRewriter
.AddRule(UndoArg1
, SW_RES(STR_OLE
));
564 EndUndo(UNDO_INSERT
, &aRewriter
);
569 // The current selected OLE object will be loaded with the
570 // verb into the server.
572 void SwWrtShell::LaunchOLEObj( long nVerb
)
574 if ( GetCntType() == CNT_OLE
&&
575 !GetView().GetViewFrame()->GetFrame().IsInPlace() )
577 svt::EmbeddedObjectRef
& xRef
= GetOLEObject();
578 OSL_ENSURE( xRef
.is(), "OLE not found" );
579 SfxInPlaceClient
* pCli
=0;
581 pCli
= GetView().FindIPClient( xRef
.GetObject(), &GetView().GetEditWin() );
583 pCli
= new SwOleClient( &GetView(), &GetView().GetEditWin(), xRef
);
585 ((SwOleClient
*)pCli
)->SetInDoVerb( sal_True
);
587 CalcAndSetScale( xRef
);
588 pCli
->DoVerb( nVerb
);
590 ((SwOleClient
*)pCli
)->SetInDoVerb( sal_False
);
591 CalcAndSetScale( xRef
);
595 void SwWrtShell::MoveObjectIfActive( svt::EmbeddedObjectRef
& xObj
, const Point
& rOffset
)
599 sal_Int32 nState
= xObj
->getCurrentState();
600 if ( nState
== ::com::sun::star::embed::EmbedStates::INPLACE_ACTIVE
601 || nState
== ::com::sun::star::embed::EmbedStates::UI_ACTIVE
)
603 SfxInPlaceClient
* pCli
=
604 GetView().FindIPClient( xObj
.GetObject(), &(GetView().GetEditWin()) );
607 Rectangle aArea
= pCli
->GetObjArea();
609 pCli
->SetObjArea( aArea
);
613 catch (const uno::Exception
&)
618 void SwWrtShell::CalcAndSetScale( svt::EmbeddedObjectRef
& xObj
,
619 const SwRect
*pFlyPrtRect
,
620 const SwRect
*pFlyFrmRect
,
621 const bool bNoTxtFrmPrtAreaChanged
)
623 // Setting the scale of the client. This arises from the difference
624 // between the VisArea of the object and the ObjArea.
625 OSL_ENSURE( xObj
.is(), "ObjectRef not valid" );
627 sal_Int64 nAspect
= xObj
.GetViewAspect();
628 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
629 return; // the replacement image is completely controlled by container in this case
632 bool bLinkingChart
= false;
636 nMisc
= xObj
->getStatus( nAspect
);
638 // This can surely only be a non-active object, if desired they
639 // get the new size set as VisArea (StarChart).
640 if( embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE
& nMisc
)
643 SwRect
aRect( pFlyPrtRect
? *pFlyPrtRect
644 : GetAnyCurRect( RECT_FLY_PRT_EMBEDDED
, 0, xObj
.GetObject() ));
645 if( !aRect
.IsEmpty() )
647 // TODO/LEAN: getMapUnit can switch object to running state
648 // xObj.TryRunningState();
650 MapUnit aUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
652 // TODO/LATER: needs complete VisArea?!
653 Size
aSize( OutputDevice::LogicToLogic( aRect
.SVRect(), MAP_TWIP
, aUnit
).GetSize() );
655 aSz
.Width
= aSize
.Width();
656 aSz
.Height
= aSize
.Height();
657 xObj
->setVisualAreaSize( nAspect
, aSz
);
658 // #i48419# - action 'UpdateReplacement' doesn't
659 // have to change the modified state of the document.
660 // This is only a workaround for the defect, that this action
661 // modifies a document after load, because unnecessarily the
662 // replacement graphic is updated, in spite of the fact that
663 // nothing has been changed.
664 // If the replacement graphic changes by this action, the document
665 // will be already modified via other mechanisms.
667 bool bResetEnableSetModified(false);
668 if ( GetDoc()->GetDocShell()->IsEnableSetModified() )
670 GetDoc()->GetDocShell()->EnableSetModified( sal_False
);
671 bResetEnableSetModified
= true;
674 //#i79576# don't destroy chart replacement images on load
675 //#i79578# don't request a new replacement image for charts to often
676 //a chart sends a modified call to the framework if it was changed
677 //thus the replacement update is already handled elsewhere
678 if ( !SotExchange::IsChart( xObj
->getClassID() ) )
679 xObj
.UpdateReplacement();
681 if ( bResetEnableSetModified
)
683 GetDoc()->GetDocShell()->EnableSetModified( sal_True
);
688 // TODO/LATER: this is only a workaround,
689 uno::Reference
< chart2::XChartDocument
> xChartDocument( xObj
->getComponent(), uno::UNO_QUERY
);
690 bLinkingChart
= ( xChartDocument
.is() && !xChartDocument
->hasInternalDataProvider() );
693 catch (const uno::Exception
&)
695 // TODO/LATER: handle the error
699 SfxInPlaceClient
* pCli
= GetView().FindIPClient( xObj
.GetObject(), &GetView().GetEditWin() );
702 if ( (embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY
& nMisc
)
704 // TODO/LATER: ResizeOnPrinterChange
705 //|| SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & xObj->GetMiscStatus()
706 // --> OD #i117189# - refine condition for non-resizable objects
707 // non-resizable objects need to be set the size back by this method
708 || ( bNoTxtFrmPrtAreaChanged
&& nMisc
& embed::EmbedMisc::EMBED_NEVERRESIZE
) )
710 pCli
= new SwOleClient( &GetView(), &GetView().GetEditWin(), xObj
);
716 // TODO/LEAN: getMapUnit can switch object to running state
717 // xObj.TryRunningState();
722 aSize
= xObj
->getVisualAreaSize( nAspect
);
724 catch (const embed::NoVisualAreaSizeException
&)
726 OSL_FAIL("Can't get visual area size!\n" );
727 // the scaling will not be done
729 catch (const uno::Exception
&)
731 // TODO/LATER: handle the error
732 OSL_FAIL("Can't get visual area size!\n" );
736 Size
_aVisArea( aSize
.Width
, aSize
.Height
);
738 Fraction
aScaleWidth( 1, 1 );
739 Fraction
aScaleHeight( 1, 1 );
741 bool bUseObjectSize
= false;
743 // As long as there comes no reasonable size from the object,
744 // nothing can be scaled.
745 if( _aVisArea
.Width() && _aVisArea
.Height() )
747 const MapMode
aTmp( MAP_TWIP
);
748 MapUnit aUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
749 _aVisArea
= OutputDevice::LogicToLogic( _aVisArea
, aUnit
, aTmp
);
752 aObjArea
= pFlyPrtRect
->SSize();
754 aObjArea
= GetAnyCurRect( RECT_FLY_PRT_EMBEDDED
, 0, xObj
.GetObject() ).SSize();
756 // differ the aObjArea and _aVisArea by 1 Pixel then set new VisArea
758 SwSelPaintRects::Get1PixelInLogic( *this, &nX
, &nY
);
759 if( !( _aVisArea
.Width() - nX
<= aObjArea
.Width() &&
760 _aVisArea
.Width() + nX
>= aObjArea
.Width() &&
761 _aVisArea
.Height()- nY
<= aObjArea
.Height()&&
762 _aVisArea
.Height()+ nY
>= aObjArea
.Height() ))
764 // TODO/LATER: MISCSTATUS_RESIZEONPRINTERCHANGE
766 if( SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & nMisc )
768 //This type of objects should never be resized.
769 //If this request comes from the Writer core (inaktive Object
770 //ist resized), the Object should be resized too.
771 //If this request comes from the Object itself, the Frame
772 //in the Writer core should be resized.
773 if ( pFlyPrtRect ) //Request from core?
775 xObj->SetVisArea( OutputDevice::LogicToLogic(
776 pFlyPrtRect->SVRect(), MAP_TWIP, xObj->GetMapUnit() ));
780 SwRect aTmp( Point( LONG_MIN, LONG_MIN ), _aVisArea );
781 RequestObjectResize( aTmp, xObj );
783 // The rest will be done, because we need to come back anyway,
784 // possibly even recursively.
789 if ( nMisc
& embed::EmbedMisc::EMBED_NEVERRESIZE
)
791 // the object must not be scaled,
792 // the size stored in object must be used for restoring
793 bUseObjectSize
= true;
797 aScaleWidth
= Fraction( aObjArea
.Width(), _aVisArea
.Width() );
798 aScaleHeight
= Fraction( aObjArea
.Height(), _aVisArea
.Height());
803 // Now is the favorable time to set the ObjArea.
804 // The Scaling must be considered.
808 aArea
= *pFlyPrtRect
;
809 aArea
+= pFlyFrmRect
->Pos();
813 aArea
= GetAnyCurRect( RECT_FLY_PRT_EMBEDDED
, 0, xObj
.GetObject() );
814 aArea
.Pos() += GetAnyCurRect( RECT_FLY_EMBEDDED
, 0, xObj
.GetObject() ).Pos();
817 if ( bUseObjectSize
)
819 // --> this moves non-resizable object so that when adding borders the baseline remains the same
820 const SwFlyFrmFmt
*pFlyFrmFmt
= dynamic_cast< const SwFlyFrmFmt
* >( GetFlyFrmFmt() );
821 OSL_ENSURE( pFlyFrmFmt
, "Could not find fly frame." );
824 const Point
&rPoint
= pFlyFrmFmt
->GetLastFlyFrmPrtRectPos();
825 SwRect
aRect( pFlyPrtRect
? *pFlyPrtRect
826 : GetAnyCurRect( RECT_FLY_PRT_EMBEDDED
, 0, xObj
.GetObject() ));
827 aArea
+= rPoint
- aRect
.Pos(); // adjust area by diff of printing area position in order to keep baseline alignment correct.
829 aArea
.Width ( _aVisArea
.Width() );
830 aArea
.Height( _aVisArea
.Height() );
831 RequestObjectResize( aArea
, xObj
.GetObject() );
835 aArea
.Width ( Fraction( aArea
.Width() ) / pCli
->GetScaleWidth() );
836 aArea
.Height( Fraction( aArea
.Height() ) / pCli
->GetScaleHeight());
839 pCli
->SetObjAreaAndScale( aArea
.SVRect(), aScaleWidth
, aScaleHeight
);
844 void SwWrtShell::ConnectObj( svt::EmbeddedObjectRef
& xObj
, const SwRect
&rPrt
,
847 SfxInPlaceClient
* pCli
= GetView().FindIPClient( xObj
.GetObject(), &GetView().GetEditWin());
849 pCli
= new SwOleClient( &GetView(), &GetView().GetEditWin(), xObj
);
850 CalcAndSetScale( xObj
, &rPrt
, &rFrm
);
853 // Insert hard page break;
854 // Selections will be overwritten
856 void SwWrtShell::InsertPageBreak(const String
*pPageDesc
, sal_uInt16 nPgNum
)
861 SwActContext
aActContext(this);
862 StartUndo(UNDO_UI_INSERT_PAGE_BREAK
);
864 if ( !IsCrsrInTbl() )
868 SwFEShell::SplitNode();
869 // delete the numbered attribute of the last line if the last line is empty
870 GetDoc()->ClearLineNumAttrs( *GetCrsr()->GetPoint() );
873 const SwPageDesc
*pDesc
= pPageDesc
874 ? FindPageDescByName( *pPageDesc
, sal_True
) : 0;
877 SwFmtPageDesc
aDesc( pDesc
);
878 aDesc
.SetNumOffset( nPgNum
);
882 SetAttr( SvxFmtBreakItem(SVX_BREAK_PAGE_BEFORE
, RES_BREAK
) );
883 EndUndo(UNDO_UI_INSERT_PAGE_BREAK
);
887 // Insert hard page break;
888 // Selections will be overwritten
890 void SwWrtShell::InsertLineBreak()
898 const sal_Unicode cIns
= 0x0A;
899 SvxAutoCorrect
* pACorr
= lcl_IsAutoCorr();
901 AutoCorrect( *pACorr
, cIns
);
903 SwWrtShell::Insert( OUString( cIns
) );
907 // Insert hard column break;
908 // Selections will be overwritten
910 void SwWrtShell::InsertColumnBreak()
912 SwActContext
aActContext(this);
916 StartUndo(UNDO_UI_INSERT_COLUMN_BREAK
);
918 if ( !IsCrsrInTbl() )
922 SwFEShell::SplitNode( sal_False
, sal_False
);
924 SetAttr(SvxFmtBreakItem(SVX_BREAK_COLUMN_BEFORE
, RES_BREAK
));
926 EndUndo(UNDO_UI_INSERT_COLUMN_BREAK
);
931 // rStr - optional footnote mark
933 void SwWrtShell::InsertFootnote(const String
&rStr
, sal_Bool bEndNote
, sal_Bool bEdit
)
940 //collapse cursor to the end
945 SwPosition aPos
= *GetCrsr()->GetPoint();
946 SwFmtFtn
aFootNote( bEndNote
);
948 aFootNote
.SetNumStr( rStr
);
954 // For editing the footnote text.
955 Left(CRSR_SKIP_CHARS
, sal_False
, 1, sal_False
);
958 aNavigationMgr
.addEntry(aPos
);
962 // SplitNode; also, because
963 // - of deleting selected content;
964 // - of reset of the Cursorstack if necessary.
966 void SwWrtShell::SplitNode( sal_Bool bAutoFmt
, sal_Bool bCheckTableStart
)
971 SwActContext
aActContext(this);
973 rView
.GetEditWin().FlushInBuffer();
974 sal_Bool bHasSel
= HasSelection();
977 StartUndo( UNDO_INSERT
);
981 SwFEShell::SplitNode( bAutoFmt
, bCheckTableStart
);
983 EndUndo( UNDO_INSERT
);
988 // Parameter: Optional specification of a name for the named list;
989 // this indicates a position if it is possible to convert them
990 // into a number and less than nMaxRules.
992 // To test the CharFormats at the numbering
993 // external void SetNumChrFmt( SwWrtShell*, SwNumRules& );
996 // Preconditions (as far as OD has figured out):
997 // - <SwEditShell::HasNumber()> is sal_False, if <bNum> is sal_True
998 // - <SwEditShell::HasBullet()> is sal_False, if <bNum> is sal_False
999 // Behavior of method is determined by the current situation at the current
1000 // cursor position in the document.
1001 void SwWrtShell::NumOrBulletOn(sal_Bool bNum
)
1003 // determine numbering rule found at current cursor position in the document.
1004 const SwNumRule
* pCurRule
= GetCurNumRule();
1006 StartUndo(UNDO_NUMORNONUM
);
1008 const SwNumRule
* pNumRule
= pCurRule
;
1010 // - activate outline rule respectively turning on outline rule for
1011 // current text node. But, only for turning on a numbering (<bNum> == sal_True).
1012 // - overwrite found numbering rule at current cursor position, if
1013 // no numbering rule can be retrieved from the paragraph style.
1014 bool bContinueFoundNumRule( false );
1015 bool bActivateOutlineRule( false );
1016 int nActivateOutlineLvl( MAXLEVEL
); // only relevant, if <bActivateOutlineRule> == sal_True
1017 SwTxtFmtColl
* pColl
= GetCurTxtFmtColl();
1020 // retrieve numbering rule at paragraph
1021 // style, which is found at current cursor position in the document.
1022 SwNumRule
* pCollRule
= mpDoc
->FindNumRulePtr(pColl
->GetNumRule().GetValue());
1023 // #125993# - The outline numbering rule isn't allowed
1024 // to be derived from a parent paragraph style to a derived one.
1025 // Thus check, if the found outline numbering rule is directly
1026 // set at the paragraph style <pColl>. If not, set <pCollRule> to NULL
1027 if ( pCollRule
&& pCollRule
== GetDoc()->GetOutlineNumRule() )
1029 const SwNumRule
* pDirectCollRule
=
1030 mpDoc
->FindNumRulePtr(pColl
->GetNumRule( sal_False
).GetValue());
1031 if ( !pDirectCollRule
)
1039 pNumRule
= pCollRule
;
1041 // no activation or continuation of outline numbering in Writer/Web document
1043 !dynamic_cast<SwWebDocShell
*>(GetDoc()->GetDocShell()) &&
1044 pCollRule
== GetDoc()->GetOutlineNumRule() )
1046 if ( pNumRule
== pCollRule
)
1048 // check, if text node at current cursor positioned is counted.
1049 // If not, let it been counted. Then it has to be checked,
1050 // of the outline numbering has to be activated or continued.
1051 SwTxtNode
* pTxtNode
=
1052 GetCrsr()->GetPoint()->nNode
.GetNode().GetTxtNode();
1053 if ( pTxtNode
&& !pTxtNode
->IsCountedInList() )
1055 // check, if numbering of the outline level of the paragraph
1056 // style is active. If not, activate this outline level.
1057 nActivateOutlineLvl
= pColl
->GetAssignedOutlineStyleLevel();
1058 OSL_ENSURE( pColl
->IsAssignedToListLevelOfOutlineStyle(),
1059 "<SwWrtShell::NumOrBulletOn(..)> - paragraph style with outline rule, but no outline level" );
1060 if ( pColl
->IsAssignedToListLevelOfOutlineStyle() &&
1061 pCollRule
->Get( static_cast<sal_uInt16
>(nActivateOutlineLvl
) ).GetNumberingType()
1062 == SVX_NUM_NUMBER_NONE
)
1064 // activate outline numbering
1065 bActivateOutlineRule
= true;
1069 // turning on outline numbering at current cursor position
1070 bContinueFoundNumRule
= true;
1076 // activate outline numbering, because from the precondition
1077 // it's known, that <SwEdit::HasNumber()> == sal_False
1078 bActivateOutlineRule
= true;
1079 nActivateOutlineLvl
= pColl
->GetAssignedOutlineStyleLevel();//<-end,zhaojianwei
1082 else if ( !pNumRule
)
1085 // Check, if corresponding list level of the outline numbering
1086 // has already a numbering format set.
1087 nActivateOutlineLvl
= pColl
->GetAssignedOutlineStyleLevel();//<-end,zhaojianwei,need further consideration
1088 if ( pCollRule
->Get( static_cast<sal_uInt16
>(nActivateOutlineLvl
) ).GetNumberingType()
1089 == SVX_NUM_NUMBER_NONE
)
1091 // activate outline numbering, because from the precondition
1092 // it's known, that <SwEdit::HasNumber()> == sal_False
1093 bActivateOutlineRule
= true;
1097 // turning on outline numbering at current cursor position
1098 bContinueFoundNumRule
= true;
1103 // check, if numbering of the outline level of the paragraph
1104 // style is active. If not, activate this outline level.
1105 nActivateOutlineLvl
= pColl
->GetAssignedOutlineStyleLevel();
1106 OSL_ENSURE( pColl
->IsAssignedToListLevelOfOutlineStyle(),
1107 "<SwWrtShell::NumOrBulletOn(..)> - paragraph style with outline rule, but no outline level" );
1108 if ( pColl
->IsAssignedToListLevelOfOutlineStyle() &&
1109 pCollRule
->Get( static_cast<sal_uInt16
>(nActivateOutlineLvl
) ).GetNumberingType()
1110 == SVX_NUM_NUMBER_NONE
)
1112 // activate outline numbering
1113 bActivateOutlineRule
= true;
1117 // turning on outline numbering at current cursor position
1118 bContinueFoundNumRule
= true;
1121 pNumRule
= pCollRule
;
1125 // Only automatic numbering/bullet rules should be changed.
1126 // Note: The outline numbering rule is also an automatic one. It's only
1127 // changed, if it has to be activated.
1130 if ( !pNumRule
->IsAutoRule() )
1134 else if ( pNumRule
== GetDoc()->GetOutlineNumRule() &&
1135 !bActivateOutlineRule
&& !bContinueFoundNumRule
)
1141 // Search for a previous numbering/bullet rule to continue it.
1142 String sContinuedListId
;
1145 pNumRule
= GetDoc()->SearchNumRule( *GetCrsr()->GetPoint(),
1146 false, bNum
, false, 0,
1148 bContinueFoundNumRule
= pNumRule
!= 0;
1153 SwNumRule
aNumRule(*pNumRule
);
1155 // do not change found numbering/bullet rule, if it should only be continued.
1156 if ( !bContinueFoundNumRule
)
1158 SwTxtNode
* pTxtNode
= GetCrsr()->GetPoint()->nNode
.GetNode().GetTxtNode();
1162 // use above retrieve outline level, if outline numbering has to be activated.
1163 int nLevel
= bActivateOutlineRule
1164 ? nActivateOutlineLvl
1165 : pTxtNode
->GetActualListLevel();
1170 if (nLevel
>= MAXLEVEL
)
1171 nLevel
= MAXLEVEL
- 1;
1173 SwNumFmt
aFmt(aNumRule
.Get(static_cast<sal_uInt16
>(nLevel
)));
1176 aFmt
.SetNumberingType(SVX_NUM_ARABIC
);
1179 // #i63395# Only apply user defined default bullet font
1180 if ( numfunc::IsDefBulletFontUserDefined() )
1182 const Font
* pFnt
= &numfunc::GetDefBulletFont();
1183 aFmt
.SetBulletFont( pFnt
);
1185 aFmt
.SetBulletChar( numfunc::GetBulletChar(static_cast<sal_uInt8
>(nLevel
)));
1186 aFmt
.SetNumberingType(SVX_NUM_CHAR_SPECIAL
);
1187 // #i93908# clear suffix for bullet lists
1188 aFmt
.SetPrefix(OUString());
1189 aFmt
.SetSuffix(OUString());
1191 aNumRule
.Set(static_cast<sal_uInt16
>(nLevel
), aFmt
);
1195 // reset indent attribute on applying list style
1196 SetCurNumRule( aNumRule
, false, sContinuedListId
, true );
1201 const SvxNumberFormat::SvxNumPositionAndSpaceMode
ePosAndSpaceMode(
1202 numfunc::GetDefaultPositionAndSpaceMode() );
1203 SwNumRule
aNumRule( GetUniqueNumRuleName(), ePosAndSpaceMode
);
1204 // Append the character template at the numbering.
1206 SwDocShell
* pDocSh
= GetView().GetDocShell();
1208 // Only apply user defined default bullet font
1209 const Font
* pFnt
= numfunc::IsDefBulletFontUserDefined()
1210 ? &numfunc::GetDefBulletFont()
1215 pChrFmt
= GetCharFmtFromPool( RES_POOLCHR_NUM_LEVEL
);
1219 pChrFmt
= GetCharFmtFromPool( RES_POOLCHR_BUL_LEVEL
);
1222 const SwTxtNode
* pTxtNode
= GetCrsr()->GetPoint()->nNode
.GetNode().GetTxtNode();
1223 const SwTwips nWidthOfTabs
= pTxtNode
1224 ? pTxtNode
->GetWidthOfLeadingTabs()
1226 GetDoc()->RemoveLeadingWhiteSpace( *GetCrsr()->GetPoint() );
1228 const bool bHtml
= 0 != PTR_CAST(SwWebDocShell
, pDocSh
);
1229 const bool bRightToLeft
= IsInRightToLeftText();
1230 for( sal_uInt8 nLvl
= 0; nLvl
< MAXLEVEL
; ++nLvl
)
1232 SwNumFmt
aFmt( aNumRule
.Get( nLvl
) );
1233 aFmt
.SetCharFmt( pChrFmt
);
1238 // Only apply user defined default bullet font
1241 aFmt
.SetBulletFont( pFnt
);
1243 aFmt
.SetBulletChar( numfunc::GetBulletChar(nLvl
) );
1244 aFmt
.SetNumberingType(SVX_NUM_CHAR_SPECIAL
);
1245 // #i93908# clear suffix for bullet lists
1246 aFmt
.SetPrefix(OUString());
1247 aFmt
.SetSuffix(OUString());
1251 if ( ePosAndSpaceMode
== SvxNumberFormat::LABEL_WIDTH_AND_POSITION
)
1256 aFmt
.SetLSpace(720);
1257 aFmt
.SetAbsLSpace(nLvl
* 720);
1259 else if ( nWidthOfTabs
> 0 )
1261 aFmt
.SetAbsLSpace(nWidthOfTabs
+ nLvl
* 720);
1265 // #i38904# Default alignment for
1266 // numbering/bullet should be rtl in rtl paragraph:
1269 aFmt
.SetNumAdjust( SVX_ADJUST_RIGHT
);
1272 aNumRule
.Set( nLvl
, aFmt
);
1277 ePosAndSpaceMode
== SvxNumberFormat::LABEL_ALIGNMENT
)
1280 const SwTwips nTxtNodeIndent
= pTxtNode
->GetAdditionalIndentForStartingNewList();
1281 if ( ( nTxtNodeIndent
+ nWidthOfTabs
) != 0 )
1284 // If text node is already inside a list, assure that the indents
1285 // are the same. Thus, adjust the indent change value by subtracting
1286 // indents of to be applied list style.
1287 SwTwips nIndentChange
= nTxtNodeIndent
+ nWidthOfTabs
;
1288 if ( pTxtNode
->GetNumRule() )
1290 const SwNumFmt
aFmt( aNumRule
.Get( 0 ) );
1291 if ( aFmt
.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT
)
1293 nIndentChange
-= aFmt
.GetIndentAt() + aFmt
.GetFirstLineIndent();
1296 aNumRule
.ChangeIndent( nIndentChange
);
1299 // reset indent attribute on applying list style
1301 SetCurNumRule( aNumRule
, true, String(), true );
1304 EndUndo(UNDO_NUMORNONUM
);
1308 void SwWrtShell::NumOn()
1310 NumOrBulletOn(sal_True
);
1313 void SwWrtShell::NumOrBulletOff()
1315 const SwNumRule
* pCurNumRule
= GetCurNumRule();
1319 if (pCurNumRule
->IsOutlineRule())
1321 SwNumRule
aNumRule(*pCurNumRule
);
1323 SwTxtNode
* pTxtNode
=
1324 GetCrsr()->GetPoint()->nNode
.GetNode().GetTxtNode();
1328 sal_uInt16 nLevel
= sal::static_int_cast
<sal_uInt16
, sal_Int32
>(pTxtNode
->GetActualListLevel());
1329 SwNumFmt
aFmt(aNumRule
.Get(nLevel
));
1331 aFmt
.SetNumberingType(SVX_NUM_NUMBER_NONE
);
1332 aNumRule
.Set(nLevel
, aFmt
);
1334 // no start or continuation of a list - the outline style is only changed.
1335 SetCurNumRule( aNumRule
, false );
1343 // #126346# - Cursor can not be anymore in front of
1344 // a label, because numbering/bullet is switched off.
1345 SetInFrontOfLabel( false );
1350 // Request Default-Bulletlist
1352 void SwWrtShell::BulletOn()
1354 NumOrBulletOn(sal_False
);
1357 SelectionType
SwWrtShell::GetSelectionType() const
1359 // ContentType cannot be determined within a
1360 // Start-/Endaction parentheses.
1361 // Because there is no invalid value TEXT will be returned.
1362 // The value does not matter, it may be updated in endaction anyway.
1364 if ( BasicActionPend() )
1365 return IsSelFrmMode() ? nsSelectionType::SEL_FRM
: nsSelectionType::SEL_TXT
;
1367 SwView
&_rView
= ((SwView
&)GetView());
1368 if (_rView
.GetPostItMgr() && _rView
.GetPostItMgr()->HasActiveSidebarWin() )
1369 return nsSelectionType::SEL_POSTIT
;
1372 // Inserting a frame is not a DrawMode
1373 if ( !_rView
.GetEditWin().IsFrmAction() &&
1374 (IsObjSelected() || (_rView
.IsDrawMode() && !IsFrmSelected()) ))
1376 if (GetDrawView()->IsTextEdit())
1377 nCnt
= nsSelectionType::SEL_DRW_TXT
;
1380 if (GetView().IsFormMode()) // Only Form selected
1381 nCnt
= nsSelectionType::SEL_DRW_FORM
;
1383 nCnt
= nsSelectionType::SEL_DRW
; // Any draw object
1385 if (_rView
.IsBezierEditMode())
1386 nCnt
|= nsSelectionType::SEL_BEZ
;
1387 else if( GetDrawView()->GetContext() == SDRCONTEXT_MEDIA
)
1388 nCnt
|= nsSelectionType::SEL_MEDIA
;
1390 if (svx::checkForSelectedCustomShapes(
1391 const_cast<SdrView
*>(GetDrawView()),
1392 true /* bOnlyExtruded */ ))
1394 nCnt
|= nsSelectionType::SEL_EXTRUDED_CUSTOMSHAPE
;
1396 sal_uInt32 nCheckStatus
= 0;
1397 if (svx::checkForSelectedFontWork(
1398 const_cast<SdrView
*>(GetDrawView()), nCheckStatus
))
1400 nCnt
|= nsSelectionType::SEL_FONTWORK
;
1407 nCnt
= GetCntType();
1409 if ( IsFrmSelected() )
1411 if (_rView
.IsDrawMode())
1412 _rView
.LeaveDrawCreate(); // clean up (Bug #45639)
1413 if ( !(nCnt
& (CNT_GRF
| CNT_OLE
)) )
1414 return nsSelectionType::SEL_FRM
;
1417 if ( IsCrsrInTbl() )
1418 nCnt
|= nsSelectionType::SEL_TBL
;
1420 if ( IsTableMode() )
1421 nCnt
|= (nsSelectionType::SEL_TBL
| nsSelectionType::SEL_TBL_CELLS
);
1424 // Do not pop up numbering toolbar, if the text node has a numbering
1425 // of type SVX_NUM_NUMBER_NONE.
1426 const SwNumRule
* pNumRule
= GetCurNumRule();
1429 const SwTxtNode
* pTxtNd
=
1430 GetCrsr()->GetPoint()->nNode
.GetNode().GetTxtNode();
1432 if ( pTxtNd
&& pTxtNd
->IsInList() )
1434 const SwNumFmt
& rFmt
= pNumRule
->Get(sal::static_int_cast
< sal_uInt8
, sal_Int32
>(pTxtNd
->GetActualListLevel()));
1435 if ( SVX_NUM_NUMBER_NONE
!= rFmt
.GetNumberingType() )
1436 nCnt
|= nsSelectionType::SEL_NUM
;
1443 // Find the text collection with the name rCollname
1444 // Returns: Pointer at the collection or 0, if no
1445 // text collection with this name exists, or
1446 // this is a default template.
1448 SwTxtFmtColl
*SwWrtShell::GetParaStyle(const String
&rCollName
, GetStyle eCreate
)
1450 SwTxtFmtColl
* pColl
= FindTxtFmtCollByName( rCollName
);
1451 if( !pColl
&& GETSTYLE_NOCREATE
!= eCreate
)
1453 sal_uInt16 nId
= SwStyleNameMapper::GetPoolIdFromUIName( rCollName
, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL
);
1454 if( USHRT_MAX
!= nId
|| GETSTYLE_CREATEANY
== eCreate
)
1455 pColl
= GetTxtCollFromPool( nId
);
1460 // Find the text collection with the name rCollname
1461 // Returns: Pointer at the collection or 0, if no
1462 // character template with this name exists, or
1463 // this is a default template or template is automatic.
1465 SwCharFmt
*SwWrtShell::GetCharStyle(const String
&rFmtName
, GetStyle eCreate
)
1467 SwCharFmt
* pFmt
= FindCharFmtByName( rFmtName
);
1468 if( !pFmt
&& GETSTYLE_NOCREATE
!= eCreate
)
1470 sal_uInt16 nId
= SwStyleNameMapper::GetPoolIdFromUIName( rFmtName
, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
);
1471 if( USHRT_MAX
!= nId
|| GETSTYLE_CREATEANY
== eCreate
)
1472 pFmt
= (SwCharFmt
*)GetFmtFromPool( nId
);
1477 // Find the table format with the name rFmtname
1478 // Returns: Pointer at the collection or 0, if no
1479 // frame format with this name exists or
1480 // this is a default format or the format is automatic.
1482 SwFrmFmt
*SwWrtShell::GetTblStyle(const String
&rFmtName
)
1485 for( sal_uInt16 i
= GetTblFrmFmtCount(); i
; )
1486 if( !( pFmt
= &GetTblFrmFmt( --i
) )->IsDefault() &&
1487 pFmt
->GetName() == rFmtName
&& IsUsed( *pFmt
) )
1492 SwNavigationMgr
& SwWrtShell::GetNavigationMgr() {
1493 return aNavigationMgr
;
1496 void SwWrtShell::addCurrentPosition() {
1497 SwPaM
* pPaM
= GetCrsr();
1498 aNavigationMgr
.addEntry(*pPaM
->GetPoint());
1501 // Applying templates
1503 void SwWrtShell::SetPageStyle(const String
&rCollName
)
1505 if( !SwCrsrShell::HasSelection() && !IsSelFrmMode() && !IsObjSelected() )
1507 SwPageDesc
* pDesc
= FindPageDescByName( rCollName
, sal_True
);
1509 ChgCurPageDesc( *pDesc
);
1515 String
SwWrtShell::GetCurPageStyle( const sal_Bool bCalcFrm
) const
1517 return GetPageDesc(GetCurPageDesc( bCalcFrm
)).GetName();
1520 // Change the current template referring to the existing change.
1522 void SwWrtShell::QuickUpdateStyle()
1524 SwTxtFmtColl
*pColl
= GetCurTxtFmtColl();
1526 // Default cannot be changed
1527 if(pColl
&& !pColl
->IsDefault())
1530 // Also apply the template to remove hard attribute assignment.
1531 SetTxtFmtColl(pColl
);
1535 void SwWrtShell::AutoUpdatePara(SwTxtFmtColl
* pColl
, const SfxItemSet
& rStyleSet
, SwPaM
* pPaM
)
1537 SwPaM
* pCrsr
= pPaM
? pPaM
: GetCrsr( );
1538 SfxItemSet
aCoreSet( GetAttrPool(),
1539 RES_CHRATR_BEGIN
, RES_CHRATR_END
- 1,
1540 RES_PARATR_BEGIN
, RES_PARATR_END
- 1,
1541 RES_FRMATR_BEGIN
, RES_FRMATR_END
- 1,
1542 SID_ATTR_TABSTOP_POS
, SID_ATTR_TABSTOP_POS
,
1543 SID_ATTR_TABSTOP_DEFAULTS
, SID_ATTR_TABSTOP_DEFAULTS
,
1544 SID_ATTR_TABSTOP_OFFSET
, SID_ATTR_TABSTOP_OFFSET
,
1545 SID_ATTR_BORDER_INNER
, SID_ATTR_BORDER_INNER
,
1546 SID_ATTR_PARA_MODEL
, SID_ATTR_PARA_KEEP
,
1547 SID_ATTR_PARA_PAGENUM
, SID_ATTR_PARA_PAGENUM
,
1549 GetPaMAttr( pCrsr
, aCoreSet
);
1550 bool bReset
= false;
1551 SfxItemIter
aParaIter( aCoreSet
);
1552 const SfxPoolItem
* pParaItem
= aParaIter
.FirstItem();
1555 if(!IsInvalidItem(pParaItem
))
1557 sal_uInt16 nWhich
= pParaItem
->Which();
1558 if(SFX_ITEM_SET
== aCoreSet
.GetItemState(nWhich
) &&
1559 SFX_ITEM_SET
== rStyleSet
.GetItemState(nWhich
))
1561 aCoreSet
.ClearItem(nWhich
);
1565 pParaItem
= aParaIter
.NextItem();
1570 ResetAttr( std::set
<sal_uInt16
>(), pCrsr
);
1571 SetAttr(aCoreSet
, 0, pCrsr
);
1573 mpDoc
->ChgFmt(*pColl
, rStyleSet
);
1577 void SwWrtShell::AutoUpdateFrame( SwFrmFmt
* pFmt
, const SfxItemSet
& rStyleSet
)
1581 ResetFlyFrmAttr( 0, &rStyleSet
);
1582 pFmt
->SetFmtAttr( rStyleSet
);
1588 void SwWrtShell::AutoCorrect( SvxAutoCorrect
& rACorr
, sal_Unicode cChar
)
1593 bool bStarted
= false;
1596 // Only parenthese here, because the regular insert
1597 // is already clipped to the editshell
1599 StartUndo(UNDO_INSERT
);
1603 SwEditShell::AutoCorrect( rACorr
, IsInsMode(), cChar
);
1608 EndUndo(UNDO_INSERT
);
1613 // Some kind of controlled copy ctor
1615 SwWrtShell::SwWrtShell( SwWrtShell
& rSh
, Window
*_pWin
, SwView
&rShell
)
1616 : SwFEShell( rSh
, _pWin
),
1620 SET_CURR_SHELL( this );
1622 SetSfxViewShell( (SfxViewShell
*)&rShell
);
1623 SetFlyMacroLnk( LINK(this, SwWrtShell
, ExecFlyMac
) );
1625 // place the cursor on the first field...
1626 IFieldmark
*pBM
= NULL
;
1627 if ( IsFormProtected() && ( pBM
= GetFieldmarkAfter( ) ) !=NULL
) {
1633 SwWrtShell::SwWrtShell( SwDoc
& rDoc
, Window
*_pWin
, SwView
&rShell
,
1634 const SwViewOption
*pViewOpt
)
1635 : SwFEShell( rDoc
, _pWin
, pViewOpt
),
1639 SET_CURR_SHELL( this );
1640 SetSfxViewShell( (SfxViewShell
*)&rShell
);
1641 SetFlyMacroLnk( LINK(this, SwWrtShell
, ExecFlyMac
) );
1643 // place the cursor on the first field...
1644 IFieldmark
*pBM
= NULL
;
1645 if ( IsFormProtected() && ( pBM
= GetFieldmarkAfter( ) ) !=NULL
) {
1650 SwWrtShell::~SwWrtShell()
1652 SET_CURR_SHELL( this );
1653 while(IsModePushed())
1655 while(PopCrsr(sal_False
))
1657 SwTransferable::ClearSelection( *this );
1660 sal_Bool
SwWrtShell::Pop( sal_Bool bOldCrsr
)
1662 sal_Bool bRet
= SwCrsrShell::Pop( bOldCrsr
);
1663 if( bRet
&& IsSelection() )
1665 fnSetCrsr
= &SwWrtShell::SetCrsrKillSel
;
1666 fnKillSel
= &SwWrtShell::ResetSelect
;
1671 bool SwWrtShell::CanInsert()
1673 return (!(IsSelFrmMode() | IsObjSelected() | (GetView().GetDrawFuncPtr() != NULL
) | (GetView().GetPostItMgr()->GetActiveSidebarWin()!= NULL
)));
1676 void SwWrtShell::ChgDBData(const SwDBData
& aDBData
)
1678 SwEditShell::ChgDBData(aDBData
);
1679 //notify the db-beamer if available
1680 GetView().NotifyDBChanged();
1683 String
SwWrtShell::GetSelDescr() const
1687 int nSelType
= GetSelectionType();
1690 case nsSelectionType::SEL_GRF
:
1691 aResult
= SW_RESSTR(STR_GRAPHIC
);
1694 case nsSelectionType::SEL_FRM
:
1696 const SwFrmFmt
* pFrmFmt
= GetCurFrmFmt();
1699 aResult
= pFrmFmt
->GetDescription();
1702 case nsSelectionType::SEL_DRW
:
1704 aResult
= SW_RESSTR(STR_DRAWING_OBJECTS
);
1709 aResult
= GetCrsrDescr();
1715 void SwWrtShell::ApplyViewOptions( const SwViewOption
&rOpt
)
1717 SwFEShell::ApplyViewOptions( rOpt
);
1718 //#i115062# invalidate meta character slot
1719 GetView().GetViewFrame()->GetBindings().Invalidate( FN_VIEW_META_CHARS
);
1723 void SwWrtShell::SetReadonlyOption(sal_Bool bSet
)
1725 GetView().GetEditWin().GetFrameControlsManager().SetReadonlyControls( bSet
);
1726 ViewShell::SetReadonlyOption( bSet
);
1729 // Switch on/off header or footer of a page style - if an empty name is
1730 // given all styles are changed
1732 void SwWrtShell::ChangeHeaderOrFooter(
1733 const String
& rStyleName
, sal_Bool bHeader
, sal_Bool bOn
, sal_Bool bShowWarning
)
1735 addCurrentPosition();
1737 StartUndo( UNDO_HEADER_FOOTER
); // #i7983#
1738 bool bExecute
= true;
1739 sal_Bool bCrsrSet
= sal_False
;
1740 for( sal_uInt16 nFrom
= 0, nTo
= GetPageDescCnt();
1741 nFrom
< nTo
; ++nFrom
)
1743 int bChgd
= sal_False
;
1744 SwPageDesc
aDesc( GetPageDesc( nFrom
));
1745 String
sTmp(aDesc
.GetName());
1746 if( !rStyleName
.Len() || rStyleName
== sTmp
)
1748 if( bShowWarning
&& !bOn
&& GetActiveView() && GetActiveView() == &GetView() &&
1749 ( (bHeader
&& aDesc
.GetMaster().GetHeader().IsActive()) ||
1750 (!bHeader
&& aDesc
.GetMaster().GetFooter().IsActive()) ) )
1752 bShowWarning
= sal_False
;
1753 //Actions have to be closed while the dialog is showing
1756 Window
* pParent
= &GetView().GetViewFrame()->GetWindow();
1757 bool bRet
= RET_YES
== QueryBox( pParent
, ResId( RID_SVXQBX_DELETE_HEADFOOT
,
1758 DIALOG_MGR() ) ).Execute();
1765 SwFrmFmt
&rMaster
= aDesc
.GetMaster();
1767 rMaster
.SetFmtAttr( SwFmtHeader( bOn
));
1769 rMaster
.SetFmtAttr( SwFmtFooter( bOn
));
1772 SvxULSpaceItem
aUL(bHeader
? 0 : MM50
, bHeader
? MM50
: 0, RES_UL_SPACE
);
1773 SwFrmFmt
* pFmt
= bHeader
?
1774 (SwFrmFmt
*)rMaster
.GetHeader().GetHeaderFmt() :
1775 (SwFrmFmt
*)rMaster
.GetFooter().GetFooterFmt();
1776 pFmt
->SetFmtAttr( aUL
);
1781 ChgPageDesc( nFrom
, aDesc
);
1783 if( !bCrsrSet
&& bOn
)
1785 if ( !IsHeaderFooterEdit() )
1786 ToggleHeaderFooterEdit();
1787 bCrsrSet
= SetCrsrInHdFt(
1788 !rStyleName
.Len() ? (sal_uInt16
)0xFFFF : nFrom
,
1794 EndUndo( UNDO_HEADER_FOOTER
); // #i7983#
1798 void SwWrtShell::SetShowHeaderFooterSeparator( FrameControlType eControl
, bool bShow
)
1800 ViewShell::SetShowHeaderFooterSeparator( eControl
, bShow
);
1802 GetView().GetEditWin().GetFrameControlsManager().HideControls( eControl
);
1805 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */