xref: /trunk/main/sw/source/ui/wrtsh/wrtsh1.cxx (revision 2b5187381cc9da7a87bafe24be64619d7f077545)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_sw.hxx"
24 
25 #include <com/sun/star/container/XChild.hpp>
26 #include <com/sun/star/embed/XVisualObject.hpp>
27 #include <com/sun/star/embed/EmbedMisc.hpp>
28 #include <com/sun/star/embed/EmbedStates.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
31 #include <com/sun/star/chart2/XChartDocument.hpp>
32 #include <com/sun/star/util/XModifiable.hpp>
33 
34 #include <math.h>   // prevent conflict between exception and std::exception
35 #include <hintids.hxx>
36 #include <svx/svdview.hxx>
37 #include <sot/factory.hxx>
38 #include <svl/itemiter.hxx>
39 #include <vcl/sound.hxx>
40 #include <tools/bigint.hxx>
41 #include <sot/storage.hxx>
42 #include <svtools/insdlg.hxx>
43 #include <sfx2/frmdescr.hxx>
44 #include <sfx2/ipclient.hxx>
45 #include <svtools/ehdl.hxx>
46 #include <svtools/soerr.hxx>
47 #include <tools/cachestr.hxx>
48 #include <unotools/moduleoptions.hxx>
49 #include <editeng/sizeitem.hxx>
50 #include <editeng/brkitem.hxx>
51 #include <editeng/svxacorr.hxx>
52 #include <vcl/graph.hxx>
53 #include <sfx2/printer.hxx>
54 #include <unotools/charclass.hxx>
55 #include <comphelper/storagehelper.hxx>
56 #include <svx/svxdlg.hxx>
57 #include <svx/extrusionbar.hxx>
58 #include <svx/fontworkbar.hxx>
59 #include <frmfmt.hxx>
60 #include <fmtftn.hxx>
61 #include <fmtpdsc.hxx>
62 #include <wdocsh.hxx>
63 #include <basesh.hxx>
64 #include <swmodule.hxx>
65 #include <wrtsh.hxx>
66 #include <view.hxx>
67 #include <uitool.hxx>
68 #include <cmdid.h>
69 #include <cfgitems.hxx>
70 #include <pagedesc.hxx>
71 #include <frmmgr.hxx>
72 #include <shellio.hxx>
73 #include <uinums.hxx> // fuer Anwenden einer
74 #include <swundo.hxx> // fuer Undo-Ids
75 #include <swcli.hxx>
76 #include <poolfmt.hxx>
77 #include <wview.hxx>
78 #include <edtwin.hxx>
79 #include <fmtcol.hxx>
80 #include <swtable.hxx>
81 #include <caption.hxx>
82 #include <viscrs.hxx>
83 #include <swdtflvr.hxx>
84 #include <crsskip.hxx>
85 #include <doc.hxx>
86 #include <wrtsh.hrc>
87 #include <SwStyleNameMapper.hxx>
88 #include <sfx2/request.hxx>
89 #include <paratr.hxx>
90 #include <ndtxt.hxx>
91 #include <editeng/acorrcfg.hxx>
92 #include <IMark.hxx>
93 #include <sfx2/bindings.hxx>
94 
95 // -> #111827#
96 #include <SwRewriter.hxx>
97 #include <comcore.hrc>
98 // <- #111827#
99 
100 #include <toolkit/helper/vclunohelper.hxx>
101 #include <sfx2/viewfrm.hxx>
102 
103 #include <editeng/acorrcfg.hxx>
104 
105 #include "PostItMgr.hxx"
106 #include <sfx2/msgpool.hxx>
107 
108 using namespace sw::mark;
109 using namespace com::sun::star;
110 
111 #define COMMON_INI_LIST \
112         fnDrag(&SwWrtShell::BeginDrag),\
113         fnSetCrsr(&SwWrtShell::SetCrsr),\
114         fnEndDrag(&SwWrtShell::EndDrag),\
115         fnKillSel(&SwWrtShell::Ignore),\
116         pModeStack(0), \
117         ePageMove(MV_NO),\
118         pCrsrStack(0),\
119         rView(rShell),\
120         bDestOnStack(sal_False), \
121         fnLeaveSelect(&SwWrtShell::SttLeaveSelect)
122 
123 #define BITFLD_INI_LIST \
124         bClearMark = \
125         bIns = sal_True;\
126         bAddMode = \
127         bBlockMode = \
128         bExtMode = \
129         bInSelect = \
130         bCopy = \
131         bLayoutMode = \
132         bNoEdit = \
133         bSelWrd = \
134         bSelLn = \
135         bIsInClickToEdit = \
136         mbRetainSelection = sal_False;
137 
138 
lcl_IsAutoCorr()139 SvxAutoCorrect* lcl_IsAutoCorr()
140 {
141     SvxAutoCorrect* pACorr = SvxAutoCorrCfg::Get()->GetAutoCorrect();
142     if( pACorr && !pACorr->IsAutoCorrFlag( CptlSttSntnc | CptlSttWrd |
143                             AddNonBrkSpace | ChgOrdinalNumber |
144                             ChgToEnEmDash | SetINetAttr | Autocorrect ))
145         pACorr = 0;
146     return pACorr;
147 }
148 
NoEdit(sal_Bool bHideCrsr)149 void SwWrtShell::NoEdit(sal_Bool bHideCrsr)
150 {
151     if(bHideCrsr)
152         HideCrsr();
153     bNoEdit = sal_True;
154 }
155 
156 
157 
Edit()158 void SwWrtShell::Edit()
159 {
160     if (CanInsert())
161     {
162         ShowCrsr();
163         bNoEdit = sal_False;
164     }
165 }
166 
167 
168 
IsEndWrd()169 sal_Bool SwWrtShell::IsEndWrd()
170 {
171     MV_CONTEXT(this);
172     if(IsEndPara() && !IsSttPara())
173         return sal_True;
174 
175     return IsEndWord();
176 }
177 
178 
179 /*------------------------------------------------------------------------
180  Beschreibung:  Abfrage, ob Einfügen moeglich ist; ggfs. Beep
181 ------------------------------------------------------------------------*/
182 
_CanInsert()183 bool SwWrtShell::_CanInsert()
184 {
185     if(!CanInsert())
186     {
187         Sound::Beep();
188         return false;
189     }
190 
191     return true;
192 }
193 
194 /*------------------------------------------------------------------------
195  Beschreibung:  String einfügen
196 ------------------------------------------------------------------------*/
197 
InsertByWord(const String & rStr)198 void SwWrtShell::InsertByWord( const String & rStr)
199 {
200     if( rStr.Len() )
201     {
202         sal_Bool bDelim = GetAppCharClass().isLetterNumeric( rStr, 0 );
203         xub_StrLen nPos = 0, nStt = 0;
204         for( ; nPos < rStr.Len(); nPos++ )
205         {
206             sal_Bool bTmpDelim = GetAppCharClass().isLetterNumeric( rStr, nPos );
207             if( bTmpDelim != bDelim )
208             {
209                 Insert( rStr.Copy( nStt, nPos - nStt ));
210                 nStt = nPos;
211             }
212         }
213         if( nStt != nPos )
214             Insert( rStr.Copy( nStt, nPos - nStt ));
215     }
216 }
217 
218 
Insert(const String & rStr)219 void SwWrtShell::Insert( const String &rStr )
220 {
221     ResetCursorStack();
222     if( !_CanInsert() )
223         return;
224 
225     sal_Bool bStarted = sal_False, bHasSel = HasSelection(),
226         bCallIns = bIns /*|| bHasSel*/;
227     bool bDeleted = false;
228 
229     if( bHasSel || ( !bIns && SelectHiddenRange() ) )
230     {
231             // nur hier klammern, da das normale Insert schon an der
232             // Editshell geklammert ist
233         StartAllAction();
234 
235         // #111827#
236         SwRewriter aRewriter;
237 
238         aRewriter.AddRule(UNDO_ARG1, GetCrsrDescr());
239         aRewriter.AddRule(UNDO_ARG2, String(SW_RES(STR_YIELDS)));
240         {
241             String aTmpStr;
242             aTmpStr += String(SW_RES(STR_START_QUOTE));
243             aTmpStr += rStr;
244             aTmpStr += String(SW_RES(STR_END_QUOTE));
245 
246             aRewriter.AddRule(UNDO_ARG3, rStr);
247         }
248 
249         StartUndo(UNDO_REPLACE, &aRewriter);
250         bStarted = sal_True;
251         bDeleted = DelRight() != 0;
252     }
253 
254     /*
255 JP 21.01.98: Ueberschreiben ueberschreibt nur die Selektion, nicht das
256             naechste Zeichen.
257     if( bHasSel && !bIns && 1 < rStr.Len() )
258     {
259         // falls mehrere Zeichen anstehen, nur das erste einfuegen,
260         // der Rest muss dann aber Ueberschrieben werden.
261         SwEditShell::Insert( rStr.GetChar( 0 ) );
262         SwEditShell::Overwrite( rStr.Copy( 1 ) );
263     }
264     else
265 */
266     bCallIns ?
267         SwEditShell::Insert2( rStr, bDeleted ) : SwEditShell::Overwrite( rStr );
268 
269 
270     if( bStarted )
271     {
272         EndAllAction();
273         EndUndo();
274     }
275 //  delete pChgFlg;
276 }
277 
278 /* Begrenzung auf maximale Hoehe geht nicht, da die maximale Hoehe
279  * des aktuellen Frames nicht erfragt werden kann. */
280 
281 
282 
Insert(const String & rPath,const String & rFilter,const Graphic & rGrf,SwFlyFrmAttrMgr * pFrmMgr,sal_Bool bRule)283 void SwWrtShell::Insert( const String &rPath, const String &rFilter,
284                          const Graphic &rGrf, SwFlyFrmAttrMgr *pFrmMgr,
285                          sal_Bool bRule )
286 {
287     ResetCursorStack();
288     if ( !_CanInsert() )
289         return;
290 
291     StartAllAction();
292 
293     SwRewriter aRewriter;
294     aRewriter.AddRule(UNDO_ARG1, SW_RES(STR_GRAPHIC));
295 
296     StartUndo(UNDO_INSERT, &aRewriter);
297 
298     if ( HasSelection() )
299         DelRight();
300         // eingefuegte Grafik in eigenen Absatz, falls am Ende
301         // eines nichtleeren Absatzes
302     //For i120928,avoid to split node
303     //if ( IsEndPara() && !IsSttPara() )
304     //  SwFEShell::SplitNode();
305 
306     EnterSelFrmMode();
307 
308     sal_Bool bSetGrfSize = sal_True;
309     sal_Bool bOwnMgr     = sal_False;
310 
311     if ( !pFrmMgr )
312     {
313         bOwnMgr = sal_True;
314         pFrmMgr = new SwFlyFrmAttrMgr( sal_True, this, FRMMGR_TYPE_GRF );
315 
316         // VORSICHT
317         // GetAttrSet nimmt einen Abgleich vor
318         // Beim Einfuegen ist eine SwFrmSize vorhanden wegen der
319         // DEF-Rahmengroesse
320         // Diese muss fuer die optimale Groesse explizit entfernt werden
321         pFrmMgr->DelAttr(RES_FRM_SIZE);
322     }
323     else
324     {
325         Size aSz( pFrmMgr->GetSize() );
326         if ( !aSz.Width() || !aSz.Height() )
327         {
328             aSz.Width() = aSz.Height() = 567;
329             pFrmMgr->SetSize( aSz );
330         }
331         else if ( aSz.Width() != DFLT_WIDTH && aSz.Height() != DFLT_HEIGHT )
332             bSetGrfSize = sal_False;
333 
334         pFrmMgr->SetHeightSizeType(ATT_FIX_SIZE);
335 
336     }
337 
338     // Einfuegen der Grafik
339     SwFEShell::Insert(rPath, rFilter, &rGrf, &pFrmMgr->GetAttrSet());
340     if ( bOwnMgr )
341         pFrmMgr->UpdateAttrMgr();
342 
343     if( bSetGrfSize && !bRule )
344     {
345         Size aGrfSize, aBound = GetGraphicDefaultSize();
346         GetGrfSize( aGrfSize );
347 
348         //Die GrafikSize noch um die Randattribute vergroessern, denn die
349         //Zaehlen beim Rahmen mit.
350         aGrfSize.Width() += pFrmMgr->CalcWidthBorder();
351         aGrfSize.Height()+= pFrmMgr->CalcHeightBorder();
352 
353         const BigInt aTempWidth( aGrfSize.Width() );
354         const BigInt aTempHeight( aGrfSize.Height());
355 
356         // ggf. Breite anpassen, Hoehe dann proportional verkleinern
357         if( aGrfSize.Width() > aBound.Width() )
358         {
359             aGrfSize.Width()  = aBound.Width();
360             aGrfSize.Height() = ((BigInt)aBound.Width()) * aTempHeight / aTempWidth;
361         }
362         // ggf. Hoehe anpassen, Breite dann proportional verkleinern
363         if( aGrfSize.Height() > aBound.Height() )
364         {
365             aGrfSize.Height() = aBound.Height();
366             aGrfSize.Width() =  ((BigInt)aBound.Height()) * aTempWidth / aTempHeight;
367         }
368         pFrmMgr->SetSize( aGrfSize );
369         pFrmMgr->UpdateFlyFrm();
370     }
371     if ( bOwnMgr )
372         delete pFrmMgr;
373 
374     EndUndo();
375     EndAllAction();
376 }
377 
378 
379 /*------------------------------------------------------------------------
380    Beschreibung: Fuegt ein OLE-Objekt in die CORE ein.
381                  Wenn kein Object uebergeben wird, so wird eins erzeugt.
382 ------------------------------------------------------------------------*/
383 
384 
InsertObject(const svt::EmbeddedObjectRef & xRef,SvGlobalName * pName,sal_Bool bActivate,sal_uInt16 nSlotId)385 void SwWrtShell::InsertObject( const svt::EmbeddedObjectRef& xRef, SvGlobalName *pName,
386                             sal_Bool bActivate, sal_uInt16 nSlotId )
387 {
388     ResetCursorStack();
389     if( !_CanInsert() )
390         return;
391 
392     if( !xRef.is() )
393     {
394         // temporary storage
395         svt::EmbeddedObjectRef xObj;
396         uno::Reference < embed::XStorage > xStor = comphelper::OStorageHelper::GetTemporaryStorage();
397         sal_Bool bDoVerb = sal_True;
398         if ( pName )
399         {
400             comphelper::EmbeddedObjectContainer aCnt( xStor );
401             ::rtl::OUString aName;
402             // TODO/LATER: get aspect?
403             xObj.Assign( aCnt.CreateEmbeddedObject( pName->GetByteSequence(), aName ), embed::Aspects::MSOLE_CONTENT );
404         }
405         else
406         {
407             SvObjectServerList aServerList;
408             switch (nSlotId)
409             {
410                 case SID_INSERT_OBJECT:
411                 {
412                     aServerList.FillInsertObjects();
413                     aServerList.Remove( SwDocShell::Factory().GetClassId() );
414                     // Intentionally no break!
415                 }
416 
417                 // TODO/LATER: recording! Convert properties to items
418                 case SID_INSERT_PLUGIN:
419                 case SID_INSERT_FLOATINGFRAME:
420                 {
421                     SfxSlotPool* pSlotPool = SW_MOD()->GetSlotPool();
422                     const SfxSlot* pSlot = pSlotPool->GetSlot(nSlotId);
423                     rtl::OString aCmd(".uno:");
424                     aCmd += pSlot->GetUnoName();
425                     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
426                     SfxAbstractInsertObjectDialog* pDlg =
427                             pFact->CreateInsertObjectDialog( GetWin(), rtl::OStringToOUString( aCmd, RTL_TEXTENCODING_UTF8 ), xStor, &aServerList );
428                     if ( pDlg )
429                     {
430                         pDlg->Execute();
431                         bDoVerb = pDlg->IsCreateNew();
432                         ::rtl::OUString aIconMediaType;
433                         uno::Reference< io::XInputStream > xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
434                         xObj.Assign( pDlg->GetObject(),
435                                      xIconMetaFile.is() ? embed::Aspects::MSOLE_ICON : embed::Aspects::MSOLE_CONTENT );
436                         if ( xIconMetaFile.is() )
437                             xObj.SetGraphicStream( xIconMetaFile, aIconMediaType );
438 
439                         DELETEZ( pDlg );
440                     }
441 
442                     break;
443                 }
444 
445                 default:
446                     break;
447             }
448         }
449 
450         if ( xObj.is() )
451         {
452             if( InsertOleObject( xObj ) && bActivate && bDoVerb )
453             {
454                 SfxInPlaceClient* pClient = GetView().FindIPClient( xObj.GetObject(), &GetView().GetEditWin() );
455                 if ( !pClient )
456                 {
457                     pClient = new SwOleClient( &GetView(), &GetView().GetEditWin(), xObj );
458                     SetCheckForOLEInCaption( sal_True );
459                 }
460 
461                 if ( xObj.GetViewAspect() == embed::Aspects::MSOLE_ICON )
462                 {
463                     SwRect aArea = GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, xObj.GetObject() );
464                     aArea.Pos() += GetAnyCurRect( RECT_FLY_EMBEDDED, 0, xObj.GetObject() ).Pos();
465                     MapMode aMapMode( MAP_TWIP );
466                     Size aSize = xObj.GetSize( &aMapMode );
467                     aArea.Width( aSize.Width() );
468                     aArea.Height( aSize.Height() );
469                     RequestObjectResize( aArea, xObj.GetObject() );
470                 }
471                 else
472                     CalcAndSetScale( xObj );
473 
474                 //#50270# Error brauchen wir nicht handeln, das erledigt das
475                 //DoVerb in der SfxViewShell
476                 pClient->DoVerb( SVVERB_SHOW );
477 
478                 // TODO/LATER: set document name - should be done in Client
479                 //if ( !ERRCODE_TOERROR( nErr ) )
480                 //  xIPObj->SetDocumentName( GetView().GetDocShell()->GetTitle() );
481             }
482         }
483     }
484     else
485     {
486         if( HasSelection() )
487             DelRight();
488         InsertOleObject( xRef );
489     }
490 }
491 
492 /*------------------------------------------------------------------------
493  Beschreibung:   Object in die Core einfuegen.
494                  Vom ClipBoard oder Insert
495 ------------------------------------------------------------------------*/
496 
InsertOleObject(const svt::EmbeddedObjectRef & xRef,SwFlyFrmFmt ** pFlyFrmFmt)497 sal_Bool SwWrtShell::InsertOleObject( const svt::EmbeddedObjectRef& xRef, SwFlyFrmFmt **pFlyFrmFmt )
498 {
499     ResetCursorStack();
500     StartAllAction();
501 
502     StartUndo(UNDO_INSERT);
503 
504     //Some differences between Math and any other objects:
505     //1. Selections should be deleted. For Math the Text should be
506     //   passed to the Object
507     //2. If the cursor is at the end of an non empty paragraph a paragraph
508     //   break should be inserted. Math objects are character bound and
509     //   no break should be inserted.
510     //3. If an selection is passed to a Math object, this object should
511     //   not be activated. sal_False should be returned then.
512     sal_Bool bStarMath = sal_True;
513     sal_Bool bActivate = sal_True;
514 
515     // set parent to get correct VisArea(in case of object needing parent printer)
516     uno::Reference < container::XChild > xChild( xRef.GetObject(), uno::UNO_QUERY );
517     if ( xChild.is() )
518         xChild->setParent( pDoc->GetDocShell()->GetModel() );
519 
520     SvGlobalName aCLSID( xRef->getClassID() );
521     bStarMath = ( SotExchange::IsMath( aCLSID ) != 0 );
522     if( IsSelection() )
523     {
524         if( bStarMath )
525         {
526             String aMathData;
527             GetSelectedText( aMathData, GETSELTXT_PARABRK_TO_ONLYCR );
528 
529             if( aMathData.Len() && svt::EmbeddedObjectRef::TryRunningState( xRef.GetObject() ) )
530             {
531                 uno::Reference < beans::XPropertySet > xSet( xRef->getComponent(), uno::UNO_QUERY );
532                 if ( xSet.is() )
533                 {
534                     try
535                     {
536                         xSet->setPropertyValue( ::rtl::OUString::createFromAscii("Formula"), uno::makeAny( ::rtl::OUString( aMathData ) ) );
537                         bActivate = sal_False;
538                     }
539                     catch ( uno::Exception& )
540                     {
541                     }
542                 }
543             }
544         }
545         DelRight();
546     }
547 
548     if ( !bStarMath )
549         SwFEShell::SplitNode( sal_False, sal_False );
550 
551     EnterSelFrmMode();
552 
553     SwFlyFrmAttrMgr aFrmMgr( sal_True, this, FRMMGR_TYPE_OLE );
554     aFrmMgr.SetHeightSizeType(ATT_FIX_SIZE);
555 
556     SwRect aBound;
557     CalcBoundRect( aBound, aFrmMgr.GetAnchor() );
558 
559     // The Size should be suggested by the OLE server
560     MapMode aMapMode( MAP_TWIP );
561     Size aSz = xRef.GetSize( &aMapMode );
562 
563     // Object size can be limited
564     if ( aSz.Width() > aBound.Width() )
565     {
566         //Immer proportional begrenzen.
567         aSz.Height() = aSz.Height() * aBound.Width() / aSz.Width();
568         aSz.Width() = aBound.Width();
569     }
570     aFrmMgr.SetSize( aSz );
571     SwFlyFrmFmt *pFmt = SwFEShell::InsertObject( xRef, &aFrmMgr.GetAttrSet() );
572 
573     // --> #i972#
574     if ( bStarMath && pDoc->get( IDocumentSettingAccess::MATH_BASELINE_ALIGNMENT ) )
575         AlignFormulaToBaseline( xRef.GetObject() );
576     // <--
577 
578     if (pFlyFrmFmt)
579         *pFlyFrmFmt = pFmt;
580 
581     if ( SotExchange::IsChart( aCLSID ) )
582     {
583         uno::Reference< embed::XEmbeddedObject > xEmbeddedObj( xRef.GetObject(), uno::UNO_QUERY );
584         if ( xEmbeddedObj.is() )
585         {
586             bool bDisableDataTableDialog = false;
587             svt::EmbeddedObjectRef::TryRunningState( xEmbeddedObj );
588             uno::Reference< beans::XPropertySet > xProps( xEmbeddedObj->getComponent(), uno::UNO_QUERY );
589             if ( xProps.is() &&
590                  ( xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DisableDataTableDialog" ) ) ) >>= bDisableDataTableDialog ) &&
591                  bDisableDataTableDialog )
592             {
593                 xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DisableDataTableDialog" ) ),
594                     uno::makeAny( sal_False ) );
595                 xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DisableComplexChartTypes" ) ),
596                     uno::makeAny( sal_False ) );
597                 uno::Reference< util::XModifiable > xModifiable( xProps, uno::UNO_QUERY );
598                 if ( xModifiable.is() )
599                 {
600                     xModifiable->setModified( sal_True );
601                 }
602             }
603         }
604     }
605 
606     EndAllAction();
607     GetView().AutoCaption(OLE_CAP, &aCLSID);
608 
609     SwRewriter aRewriter;
610 
611     if ( bStarMath )
612         aRewriter.AddRule(UNDO_ARG1, SW_RES(STR_MATH_FORMULA));
613     else if ( SotExchange::IsChart( aCLSID ) )
614         aRewriter.AddRule(UNDO_ARG1, SW_RES(STR_CHART));
615     else
616         aRewriter.AddRule(UNDO_ARG1, SW_RES(STR_OLE));
617 
618     EndUndo(UNDO_INSERT, &aRewriter);
619 
620     return bActivate;
621 }
622 
623 /*------------------------------------------------------------------------
624     Beschreibung: Das aktuelle selektierte OLE-Objekt wird mit dem
625                   Verb in den Server geladen.
626 ------------------------------------------------------------------------*/
627 
628 
629 
LaunchOLEObj(long nVerb)630 void SwWrtShell::LaunchOLEObj( long nVerb )
631 {
632     if ( GetCntType() == CNT_OLE &&
633         !GetView().GetViewFrame()->GetFrame().IsInPlace() )
634     {
635         svt::EmbeddedObjectRef& xRef = GetOLEObject();
636         ASSERT( xRef.is(), "OLE not found" );
637         SfxInPlaceClient* pCli=0;
638 
639         pCli = GetView().FindIPClient( xRef.GetObject(), &GetView().GetEditWin() );
640         if ( !pCli )
641             pCli = new SwOleClient( &GetView(), &GetView().GetEditWin(), xRef );
642 
643         ((SwOleClient*)pCli)->SetInDoVerb( sal_True );
644 
645         CalcAndSetScale( xRef );
646         pCli->DoVerb( nVerb );
647 
648         ((SwOleClient*)pCli)->SetInDoVerb( sal_False );
649         CalcAndSetScale( xRef );
650     }
651 }
652 
MoveObjectIfActive(svt::EmbeddedObjectRef & xObj,const Point & rOffset)653 void SwWrtShell::MoveObjectIfActive( svt::EmbeddedObjectRef& xObj, const Point& rOffset )
654 {
655     try
656     {
657         sal_Int32 nState = xObj->getCurrentState();
658         if ( nState == ::com::sun::star::embed::EmbedStates::INPLACE_ACTIVE
659              || nState == ::com::sun::star::embed::EmbedStates::UI_ACTIVE )
660         {
661             SfxInPlaceClient* pCli =
662                 GetView().FindIPClient( xObj.GetObject(), &(GetView().GetEditWin()) );
663             if ( pCli )
664             {
665                 Rectangle aArea = pCli->GetObjArea();
666                 aArea += rOffset;
667                 pCli->SetObjArea( aArea );
668             }
669         }
670     }
671     catch( uno::Exception& )
672     {}
673 }
674 
675 
CalcAndSetScale(svt::EmbeddedObjectRef & xObj,const SwRect * pFlyPrtRect,const SwRect * pFlyFrmRect,const bool bNoTxtFrmPrtAreaChanged)676 void SwWrtShell::CalcAndSetScale( svt::EmbeddedObjectRef& xObj,
677                                   const SwRect *pFlyPrtRect,
678                                   const SwRect *pFlyFrmRect,
679                                   const bool bNoTxtFrmPrtAreaChanged )
680 {
681     //Einstellen der Skalierung am Client. Diese ergibt sich aus der Differenz
682     //zwischen der VisArea des Objektes und der ObjArea.
683     ASSERT( xObj.is(), "ObjectRef not valid" );
684 
685     sal_Int64 nAspect = xObj.GetViewAspect();
686     if ( nAspect == embed::Aspects::MSOLE_ICON )
687         return; // the replacement image is completely controlled by container in this case
688 
689     sal_Int64 nMisc = 0;
690     sal_Bool bLinkingChart = sal_False;
691 
692     try
693     {
694         nMisc = xObj->getStatus( nAspect );
695 
696         //Das kann ja wohl nur ein nicht aktives Objekt sein. Diese bekommen
697         //auf Wunsch die neue Groesse als VisArea gesetzt (Chart)
698         if( embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE & nMisc )
699         {
700             // TODO/MBA: testing
701             SwRect aRect( pFlyPrtRect ? *pFlyPrtRect
702                         : GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, xObj.GetObject() ));
703             if( !aRect.IsEmpty() )
704             {
705                 // TODO/LEAN: getMapUnit can switch object to running state
706                 // xObj.TryRunningState();
707 
708                 MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
709 
710                 // TODO/LATER: needs complete VisArea?!
711                 Size aSize( OutputDevice::LogicToLogic( aRect.SVRect(), MAP_TWIP, aUnit ).GetSize() );
712                 awt::Size aSz;
713                 aSz.Width = aSize.Width();
714                 aSz.Height = aSize.Height();
715                 xObj->setVisualAreaSize( nAspect, aSz );
716                 // --> OD 2005-05-02 #i48419# - action 'UpdateReplacement' doesn't
717                 // have to change the modified state of the document.
718                 // This is only a workaround for the defect, that this action
719                 // modifies a document after load, because unnecessarily the
720                 // replacement graphic is updated, in spite of the fact that
721                 // nothing has been changed.
722                 // If the replacement graphic changes by this action, the document
723                 // will be already modified via other mechanisms.
724                 {
725                     bool bResetEnableSetModified(false);
726                     if ( GetDoc()->GetDocShell()->IsEnableSetModified() )
727                     {
728                         GetDoc()->GetDocShell()->EnableSetModified( sal_False );
729                         bResetEnableSetModified = true;
730                     }
731 
732                     //#i79576# don't destroy chart replacement images on load
733                     //#i79578# don't request a new replacement image for charts to often
734                     //a chart sends a modified call to the framework if it was changed
735                     //thus the replacement update is already handled elsewhere
736                     if ( !SotExchange::IsChart( xObj->getClassID() ) )
737                         xObj.UpdateReplacement();
738 
739                     if ( bResetEnableSetModified )
740                     {
741                         GetDoc()->GetDocShell()->EnableSetModified( sal_True );
742                     }
743                 }
744                 // <--
745             }
746 
747             // TODO/LATER: this is only a workaround,
748             uno::Reference< chart2::XChartDocument > xChartDocument( xObj->getComponent(), uno::UNO_QUERY );
749             bLinkingChart = ( xChartDocument.is() && !xChartDocument->hasInternalDataProvider() );
750         }
751     }
752     catch ( uno::Exception& )
753     {
754         // TODO/LATER: handle the error
755         return;
756     }
757 
758     SfxInPlaceClient* pCli = GetView().FindIPClient( xObj.GetObject(), &GetView().GetEditWin() );
759     if ( !pCli )
760     {
761         if ( (embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY & nMisc)
762              || bLinkingChart
763             // TODO/LATER: ResizeOnPrinterChange
764              //|| SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & xObj->GetMiscStatus()
765              // --> OD #i117189# - refine condition for non-resizable objects
766              // non-resizable objects need to be set the size back by this method
767              || ( bNoTxtFrmPrtAreaChanged && nMisc & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
768         {
769             pCli = new SwOleClient( &GetView(), &GetView().GetEditWin(), xObj );
770         }
771         else
772             return;
773     }
774 
775     // TODO/LEAN: getMapUnit can switch object to running state
776     // xObj.TryRunningState();
777 
778     awt::Size aSize;
779     try
780     {
781         aSize = xObj->getVisualAreaSize( nAspect );
782     }
783     catch( embed::NoVisualAreaSizeException& )
784     {
785         DBG_ERROR( "Can't get visual area size!\n" );
786         // the scaling will not be done
787     }
788     catch( uno::Exception& )
789     {
790         // TODO/LATER: handle the error
791         DBG_ERROR( "Can't get visual area size!\n" );
792         return;
793     }
794 
795     Size _aVisArea( aSize.Width, aSize.Height );
796 
797     Fraction aScaleWidth( 1, 1 );
798     Fraction aScaleHeight( 1, 1 );
799 
800     sal_Bool bUseObjectSize = sal_False;
801 
802     // solange keine vernuenftige Size vom Object kommt, kann nichts
803     // skaliert werden
804     if( _aVisArea.Width() && _aVisArea.Height() )
805     {
806         const MapMode aTmp( MAP_TWIP );
807         MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
808         _aVisArea = OutputDevice::LogicToLogic( _aVisArea, aUnit, aTmp);
809         Size aObjArea;
810         if ( pFlyPrtRect )
811             aObjArea = pFlyPrtRect->SSize();
812         else
813             aObjArea = GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, xObj.GetObject() ).SSize();
814 
815         // differ the aObjArea and _aVisArea by 1 Pixel then set new VisArea
816         long nX, nY;
817         SwSelPaintRects::Get1PixelInLogic( *this, &nX, &nY );
818         if( !( _aVisArea.Width() - nX <= aObjArea.Width() &&
819                _aVisArea.Width() + nX >= aObjArea.Width() &&
820                _aVisArea.Height()- nY <= aObjArea.Height()&&
821                _aVisArea.Height()+ nY >= aObjArea.Height() ))
822         {
823             // TODO/LATER: MISCSTATUS_RESIZEONPRINTERCHANGE
824             /*
825             if( SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & nMisc )
826             {
827                 //This type of objects should never be resized.
828                 //If this request comes from the Writer core (inaktive Object
829                 //ist resized), the Object should be resized too.
830                 //If this request comes from the Object itself, the Frame
831                 //in the Writer core should be resized.
832                 if ( pFlyPrtRect )      //Request from core?
833                 {
834                     xObj->SetVisArea( OutputDevice::LogicToLogic(
835                         pFlyPrtRect->SVRect(), MAP_TWIP, xObj->GetMapUnit() ));
836                 }
837                 else
838                 {
839                     SwRect aTmp( Point( LONG_MIN, LONG_MIN ), _aVisArea );
840                     RequestObjectResize( aTmp, xObj );
841                 }
842                 //Der Rest erledigt sich, weil wir eh wiederkommen sollten, evtl.
843                 //sogar rekursiv.
844                 return;
845             }
846             else*/
847 
848             if ( nMisc & embed::EmbedMisc::EMBED_NEVERRESIZE )
849             {
850                 // the object must not be scaled, the size stored in object must be used for restoring
851                 bUseObjectSize = sal_True;
852             }
853             else
854             {
855                 aScaleWidth = Fraction( aObjArea.Width(),   _aVisArea.Width() );
856                 aScaleHeight = Fraction( aObjArea.Height(), _aVisArea.Height());
857             }
858         }
859     }
860 
861     //Jetzt ist auch der guenstige Zeitpunkt die ObjArea einzustellen.
862     //Die Skalierung muss beruecksichtigt werden.
863     SwRect aArea;
864     if ( pFlyPrtRect )
865     {
866         aArea = *pFlyPrtRect;
867         aArea += pFlyFrmRect->Pos();
868     }
869     else
870     {
871         aArea = GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, xObj.GetObject() );
872         aArea.Pos() += GetAnyCurRect( RECT_FLY_EMBEDDED, 0, xObj.GetObject() ).Pos();
873     }
874 
875     if ( bUseObjectSize )
876     {
877         // --> this moves non-resizable object so that when adding borders the baseline remains the same
878         const SwFlyFrmFmt *pFlyFrmFmt = dynamic_cast< const SwFlyFrmFmt * >( GetFlyFrmFmt() );
879         ASSERT( pFlyFrmFmt, "Could not find fly frame." );
880         if ( pFlyFrmFmt )
881         {
882             const Point &rPoint = pFlyFrmFmt->GetLastFlyFrmPrtRectPos();
883             SwRect aRect( pFlyPrtRect ? *pFlyPrtRect
884                         : GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, xObj.GetObject() ));
885             aArea += rPoint - aRect.Pos(); // adjust area by diff of printing area position in order to keep baseline alignment correct.
886         }
887         // <--
888         aArea.Width ( _aVisArea.Width() );
889         aArea.Height( _aVisArea.Height() );
890         RequestObjectResize( aArea, xObj.GetObject() );
891     }
892     else
893     {
894         aArea.Width ( Fraction( aArea.Width()  ) / pCli->GetScaleWidth() );
895         aArea.Height( Fraction( aArea.Height() ) / pCli->GetScaleHeight());
896     }
897 
898     pCli->SetObjAreaAndScale( aArea.SVRect(), aScaleWidth, aScaleHeight );
899 }
900 
901 
902 
ConnectObj(svt::EmbeddedObjectRef & xObj,const SwRect & rPrt,const SwRect & rFrm)903 void SwWrtShell::ConnectObj( svt::EmbeddedObjectRef& xObj, const SwRect &rPrt,
904                             const SwRect &rFrm )
905 {
906     SfxInPlaceClient* pCli = GetView().FindIPClient( xObj.GetObject(), &GetView().GetEditWin());
907     if ( !pCli )
908         pCli = new SwOleClient( &GetView(), &GetView().GetEditWin(), xObj );
909     CalcAndSetScale( xObj, &rPrt, &rFrm );
910 }
911 
912 /*------------------------------------------------------------------------
913  Beschreibung:  Einfügen harter Seitenumbruch;
914                 Selektionen werden überschrieben
915 ------------------------------------------------------------------------*/
916 
917 
918 
InsertPageBreak(const String * pPageDesc,sal_uInt16 nPgNum)919 void SwWrtShell::InsertPageBreak(const String *pPageDesc, sal_uInt16 nPgNum )
920 {
921     ResetCursorStack();
922     if( _CanInsert() )
923     {
924         ACT_CONTEXT(this);
925         StartUndo(UNDO_UI_INSERT_PAGE_BREAK);
926 
927         if ( !IsCrsrInTbl() )
928         {
929             if(HasSelection())
930                 DelRight();
931             SwFEShell::SplitNode();
932         }
933 
934         const SwPageDesc *pDesc = pPageDesc
935                                 ? FindPageDescByName( *pPageDesc, sal_True ) : 0;
936         if( pDesc )
937         {
938             SwFmtPageDesc aDesc( pDesc );
939             aDesc.SetNumOffset( nPgNum );
940             SetAttrItem( aDesc );
941         }
942         else
943             SetAttrItem( SvxFmtBreakItem(SVX_BREAK_PAGE_BEFORE, RES_BREAK) );
944         EndUndo(UNDO_UI_INSERT_PAGE_BREAK);
945     }
946 }
947 /*------------------------------------------------------------------------
948  Beschreibung:  Einfügen harter Zeilenumbruch;
949                 Selektionen werden überschrieben
950 ------------------------------------------------------------------------*/
951 
952 
InsertLineBreak()953 void SwWrtShell::InsertLineBreak()
954 {
955     ResetCursorStack();
956     if( _CanInsert() )
957     {
958         if(HasSelection())
959             DelRight();
960 
961         const sal_Unicode cIns = 0x0A;
962         SvxAutoCorrect* pACorr = lcl_IsAutoCorr();
963         if( pACorr )
964             AutoCorrect( *pACorr, cIns );
965         else
966             SwWrtShell::Insert( String( cIns ) );
967     }
968 }
969 /*------------------------------------------------------------------------
970  Beschreibung:  Einfügen harter Spaltenumbruch;
971                 Selektionen werden überschrieben
972 ------------------------------------------------------------------------*/
973 
974 
InsertColumnBreak()975 void SwWrtShell::InsertColumnBreak()
976 {
977     ACT_CONTEXT(this);
978     ResetCursorStack();
979     if( _CanInsert() )
980     {
981         StartUndo(UNDO_UI_INSERT_COLUMN_BREAK);
982 
983         if ( !IsCrsrInTbl() )
984         {
985             if(HasSelection())
986                 DelRight();
987             SwFEShell::SplitNode( sal_False, sal_False );
988         }
989         SetAttrItem(SvxFmtBreakItem(SVX_BREAK_COLUMN_BEFORE, RES_BREAK));
990 
991         EndUndo(UNDO_UI_INSERT_COLUMN_BREAK);
992     }
993 }
994 
995 /*------------------------------------------------------------------------
996  Beschreibung:  Einfügen Fussnote
997  Parameter:     rStr -- optionales Fussnotenzeichen
998 ------------------------------------------------------------------------*/
999 
1000 
InsertFootnote(const String & rStr,sal_Bool bEndNote,sal_Bool bEdit)1001 void SwWrtShell::InsertFootnote(const String &rStr, sal_Bool bEndNote, sal_Bool bEdit )
1002 {
1003     ResetCursorStack();
1004     if( _CanInsert() )
1005     {
1006         if(HasSelection())
1007         {
1008             //collapse cursor to the end
1009             if(!IsCrsrPtAtEnd())
1010                 SwapPam();
1011             ClearMark();
1012         }
1013 
1014         SwFmtFtn aFootNote( bEndNote );
1015         if(rStr.Len())
1016             aFootNote.SetNumStr( rStr );
1017 
1018         SetAttrItem(aFootNote);
1019 
1020         if( bEdit )
1021         {
1022             // zur Bearbeiung des Fussnotentextes
1023             Left(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
1024             GotoFtnTxt();
1025         }
1026     }
1027 }
1028 /*------------------------------------------------------------------------
1029  Beschreibung:  SplitNode; hier auch, da
1030                     - selektierter Inhalt geloescht wird;
1031                     - der Cursorstack gfs. zurueckgesetzt wird.
1032 ------------------------------------------------------------------------*/
1033 
1034 
SplitNode(sal_Bool bAutoFmt,sal_Bool bCheckTableStart)1035 void SwWrtShell::SplitNode( sal_Bool bAutoFmt, sal_Bool bCheckTableStart )
1036 {
1037     ResetCursorStack();
1038     if( _CanInsert() )
1039     {
1040         ACT_CONTEXT(this);
1041 
1042         rView.GetEditWin().FlushInBuffer();
1043         sal_Bool bHasSel = HasSelection();
1044         if( bHasSel )
1045         {
1046             StartUndo( UNDO_INSERT );
1047             DelRight();
1048         }
1049 
1050         SwFEShell::SplitNode( bAutoFmt, bCheckTableStart );
1051         if( bHasSel )
1052             EndUndo( UNDO_INSERT );
1053     }
1054 }
1055 
1056 /*------------------------------------------------------------------------
1057  Beschreibung:  Numerierung anschalten
1058  Parameter:     Optionale Angabe eines Namens für die benannte Liste;
1059                 dieser bezeichnet eine Position, wenn er in eine
1060                 Zahl konvertierbar ist und kleiner ist als nMaxRules.
1061 -------------------------------------------------------------------------*/
1062 
1063 
1064 // zum Testen der CharFormate an der Numerierung
1065 // extern void SetNumChrFmt( SwWrtShell*, SwNumRules& );
1066 
1067 // -> #i40041#
1068 // --> OD 2005-10-25 #b6340308#
1069 // Preconditions (as far as OD has figured out):
1070 // - <SwEditShell::HasNumber()> is sal_False, if <bNum> is sal_True
1071 // - <SwEditShell::HasBullet()> is sal_False, if <bNum> is sal_False
1072 // Behavior of method is determined by the current situation at the current
1073 // cursor position in the document.
NumOrBulletOn(sal_Bool bNum)1074 void SwWrtShell::NumOrBulletOn(sal_Bool bNum)
1075 {
1076     // determine numbering rule found at current cursor position in the document.
1077     const SwNumRule* pCurRule = GetNumRuleAtCurrCrsrPos();
1078 
1079     StartUndo(UNDO_NUMORNONUM);
1080 
1081     const SwNumRule * pNumRule = pCurRule;
1082 
1083     // --> OD 2005-10-25 #b6340308#
1084     // - activate outline rule respectively turning on outline rule for
1085     //   current text node. But, only for turning on a numbering (<bNum> == sal_True).
1086     // - overwrite found numbering rule at current cursor position, if
1087     //   no numbering rule can be retrieved from the paragraph style.
1088     bool bContinueFoundNumRule( false );
1089     bool bActivateOutlineRule( false );
1090     int nActivateOutlineLvl( MAXLEVEL ); // only relevant, if <bActivateOutlineRule> == sal_True
1091     SwTxtFmtColl * pColl = GetCurTxtFmtColl();
1092     if ( pColl )
1093     {
1094         // --> OD 2005-10-25 #b6340308# - retrieve numbering rule at paragraph
1095         // style, which is found at current cursor position in the document.
1096         SwNumRule* pCollRule = pDoc->FindNumRulePtr(pColl->GetNumRule().GetValue());
1097         // --> OD 2005-10-25 #125993# - The outline numbering rule isn't allowed
1098         // to be derived from a parent paragraph style to a derived one.
1099         // Thus check, if the found outline numbering rule is directly
1100         // set at the paragraph style <pColl>. If not, set <pCollRule> to NULL
1101         if ( pCollRule && pCollRule == GetDoc()->GetOutlineNumRule() )
1102         {
1103             const SwNumRule* pDirectCollRule =
1104                     pDoc->FindNumRulePtr(pColl->GetNumRule( sal_False ).GetValue());
1105             if ( !pDirectCollRule )
1106             {
1107                 pCollRule = 0;
1108             }
1109         }
1110         // --> OD 2006-11-20 #i71764#
1111         // Document setting OUTLINE_LEVEL_YIELDS_OUTLINE_RULE has no influence
1112         // any more.
1113 //      if ( pCollRule == NULL &&
1114 //          NO_NUMBERING != pColl->GetOutlineLevel() &&
1115 //          GetDoc()->get(IDocumentSettingAccess::OUTLINE_LEVEL_YIELDS_OUTLINE_RULE) )
1116 //      {
1117 //          pCollRule = GetDoc()->GetOutlineNumRule();
1118 //      }
1119         // <--
1120 
1121         // <--
1122         // --> OD 2005-10-25 #b6340308#
1123         if ( !pCollRule )
1124         {
1125             pNumRule = pCollRule;
1126         }
1127         // --> OD 2006-06-12 #b6435904#
1128         // no activation or continuation of outline numbering in Writer/Web document
1129         else if ( bNum &&
1130                   !dynamic_cast<SwWebDocShell*>(GetDoc()->GetDocShell()) &&
1131                   pCollRule == GetDoc()->GetOutlineNumRule() )
1132         // <--
1133         {
1134             if ( pNumRule == pCollRule )
1135             {
1136                 // check, if text node at current cursor positioned is counted.
1137                 // If not, let it been counted. Then it has to be checked,
1138                 // of the outline numbering has to be activated or continued.
1139                 SwTxtNode* pTxtNode =
1140                             GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
1141                 if ( pTxtNode && !pTxtNode->IsCountedInList() )
1142                 {
1143                     // check, if numbering of the outline level of the paragraph
1144                     // style is active. If not, activate this outline level.
1145                     nActivateOutlineLvl = pColl->GetAssignedOutlineStyleLevel();
1146                     ASSERT( pColl->IsAssignedToListLevelOfOutlineStyle(),   //<-end,zhaojianwei
1147                             "<SwWrtShell::NumOrBulletOn(..)> - paragraph style with outline rule, but no outline level" );
1148                     if ( pColl->IsAssignedToListLevelOfOutlineStyle() &&        //<-end,zhaojianwei
1149                          pCollRule->Get( static_cast<sal_uInt16>(nActivateOutlineLvl) ).GetNumberingType()
1150                             == SVX_NUM_NUMBER_NONE )
1151                     {
1152                         // activate outline numbering
1153                         bActivateOutlineRule = true;
1154                     }
1155                     else
1156                     {
1157                         // turning on outline numbering at current cursor position
1158                         bContinueFoundNumRule = true;
1159                     }
1160                 }
1161                 else
1162                 {
1163                     // --> OD 2009-08-27 #i101234#
1164                     // activate outline numbering, because from the precondition
1165                     // it's known, that <SwEdit::HasNumber()> == sal_False
1166                     bActivateOutlineRule = true;
1167                     nActivateOutlineLvl = pColl->GetAssignedOutlineStyleLevel();//<-end,zhaojianwei
1168                 }
1169             }
1170             else if ( !pNumRule )
1171             {
1172                 // --> OD 2009-08-27 #i101234#
1173                 // Check, if corresponding list level of the outline numbering
1174                 // has already a numbering format set.
1175                 nActivateOutlineLvl = pColl->GetAssignedOutlineStyleLevel();//<-end,zhaojianwei,need further consideration
1176                 if ( pCollRule->Get( static_cast<sal_uInt16>(nActivateOutlineLvl) ).GetNumberingType()
1177                                 == SVX_NUM_NUMBER_NONE )
1178                 {
1179                     // activate outline numbering, because from the precondition
1180                     // it's known, that <SwEdit::HasNumber()> == sal_False
1181                     bActivateOutlineRule = true;
1182                 }
1183                 else
1184                 {
1185                     // turning on outline numbering at current cursor position
1186                     bContinueFoundNumRule = true;
1187                 }
1188                 // <--
1189             }
1190             else
1191             {
1192                 // check, if numbering of the outline level of the paragraph
1193                 // style is active. If not, activate this outline level.
1194                 nActivateOutlineLvl = pColl->GetAssignedOutlineStyleLevel();//#outline level,zhaojianwei
1195                 ASSERT( pColl->IsAssignedToListLevelOfOutlineStyle(),//#outline level,zhaojianwei
1196                         "<SwWrtShell::NumOrBulletOn(..)> - paragraph style with outline rule, but no outline level" );
1197                 if ( pColl->IsAssignedToListLevelOfOutlineStyle() &&//#outline level,zhaojianwei
1198                      pCollRule->Get( static_cast<sal_uInt16>(nActivateOutlineLvl) ).GetNumberingType()
1199                         == SVX_NUM_NUMBER_NONE )
1200                 {
1201                     // activate outline numbering
1202                     bActivateOutlineRule = true;
1203                 }
1204                 else
1205                 {
1206                     // turning on outline numbering at current cursor position
1207                     bContinueFoundNumRule = true;
1208                 }
1209             }
1210             pNumRule = pCollRule;
1211         }
1212     }
1213 
1214     // --> OD 2005-10-25 #b6340308#
1215     // Only automatic numbering/bullet rules should be changed.
1216     // Note: The outline numbering rule is also an automatic one. It's only
1217     //       changed, if it has to be activated.
1218     if ( pNumRule )
1219     {
1220         if ( !pNumRule->IsAutoRule() )
1221         {
1222             pNumRule = 0;
1223         }
1224         else if ( pNumRule == GetDoc()->GetOutlineNumRule() &&
1225                   !bActivateOutlineRule && !bContinueFoundNumRule )
1226         {
1227             pNumRule = 0;
1228         }
1229     }
1230     // <--
1231 
1232     // --> OD 2005-10-25 #b6340308#
1233     // Search for a previous numbering/bullet rule to continue it.
1234     // --> OD 2008-03-18 #refactorlists#
1235     String sContinuedListId;
1236     if ( !pNumRule )
1237     {
1238         pNumRule = GetDoc()->SearchNumRule( *GetCrsr()->GetPoint(),
1239                                             false, bNum, false, 0,
1240                                             sContinuedListId );
1241         bContinueFoundNumRule = pNumRule != 0;
1242     }
1243     // <--
1244 
1245     if (pNumRule)
1246     {
1247         SwNumRule aNumRule(*pNumRule);
1248 
1249         // --> OD 2005-10-25 #b6340308#
1250         // do not change found numbering/bullet rule, if it should only be continued.
1251         if ( !bContinueFoundNumRule )
1252         {
1253             SwTxtNode * pTxtNode = GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
1254 
1255             if (pTxtNode)
1256             {
1257                 // --> OD 2005-10-26 #b6340308# - use above retrieve outline
1258                 // level, if outline numbering has to be activated.
1259                 int nLevel = bActivateOutlineRule  ////#outline level,zhaojianwei,need more consideration
1260                               ? nActivateOutlineLvl
1261                               : pTxtNode->GetActualListLevel();
1262                 // <--
1263 
1264                 if (nLevel < 0)
1265                     nLevel = 0;
1266 
1267                 if (nLevel >= MAXLEVEL)
1268                     nLevel = MAXLEVEL - 1;
1269 
1270                 SwNumFmt aFmt(aNumRule.Get(static_cast<sal_uInt16>(nLevel)));
1271 
1272                 if (bNum)
1273                     aFmt.SetNumberingType(SVX_NUM_ARABIC);
1274                 else
1275                 {
1276                     // --> OD 2008-06-03 #i63395#
1277                     // Only apply user defined default bullet font
1278                     if ( numfunc::IsDefBulletFontUserDefined() )
1279                     {
1280                         const Font* pFnt = &numfunc::GetDefBulletFont();
1281                         aFmt.SetBulletFont( pFnt );
1282                     }
1283                     // <--
1284                     aFmt.SetBulletChar( numfunc::GetBulletChar(static_cast<sal_uInt8>(nLevel)));
1285                     aFmt.SetNumberingType(SVX_NUM_CHAR_SPECIAL);
1286                     // #i93908# clear suffix for bullet lists
1287                     aFmt.SetPrefix(::rtl::OUString());
1288                     aFmt.SetSuffix(::rtl::OUString());
1289                 }
1290                 aNumRule.Set(static_cast<sal_uInt16>(nLevel), aFmt);
1291             }
1292         }
1293         // <--
1294 
1295         // --> OD 2008-02-08 #newlistlevelattrs#
1296         // reset indent attribute on applying list style
1297         // --> OD 2008-03-27 #refactorlists#
1298         SetCurNumRule( aNumRule, false, sContinuedListId, true );
1299         // <--
1300     }
1301     else
1302     {
1303         // --> OD 2009-08-27 #i95907#
1304         const SvxNumberFormat::SvxNumPositionAndSpaceMode ePosAndSpaceMode(
1305                                     numfunc::GetDefaultPositionAndSpaceMode() );
1306         // --> OD 2008-02-11 #newlistlevelattrs#
1307         SwNumRule aNumRule( GetUniqueNumRuleName(), ePosAndSpaceMode );
1308         // <--
1309         // <--
1310         // Zeichenvorlage an die Numerierung haengen
1311         SwCharFmt* pChrFmt;
1312         SwDocShell* pDocSh = GetView().GetDocShell();
1313         // --> OD 2008-06-03 #i63395#
1314         // Only apply user defined default bullet font
1315         const Font* pFnt = numfunc::IsDefBulletFontUserDefined()
1316                            ? &numfunc::GetDefBulletFont()
1317                            : 0;
1318         // <--
1319 
1320         if (bNum)
1321         {
1322             pChrFmt = GetCharFmtFromPool( RES_POOLCHR_NUM_LEVEL );
1323         }
1324         else
1325         {
1326             pChrFmt = GetCharFmtFromPool( RES_POOLCHR_BUL_LEVEL );
1327         }
1328 
1329         const SwTxtNode* pTxtNode = GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
1330         const SwTwips nWidthOfTabs = pTxtNode
1331                                      ? pTxtNode->GetWidthOfLeadingTabs()
1332                                      : 0;
1333         GetDoc()->RemoveLeadingWhiteSpace( *GetCrsr()->GetPoint() );
1334 
1335         const bool bHtml = 0 != PTR_CAST(SwWebDocShell, pDocSh);
1336         const bool bRightToLeft = IsInRightToLeftText();
1337         for( sal_uInt8 nLvl = 0; nLvl < MAXLEVEL; ++nLvl )
1338         {
1339             SwNumFmt aFmt( aNumRule.Get( nLvl ) );
1340             aFmt.SetCharFmt( pChrFmt );
1341 
1342             if (! bNum)
1343             {
1344                 // --> OD 2008-06-03 #i63395#
1345                 // Only apply user defined default bullet font
1346                 if ( pFnt )
1347                 {
1348                     aFmt.SetBulletFont( pFnt );
1349                 }
1350                 aFmt.SetBulletChar( numfunc::GetBulletChar(nLvl) );
1351                 aFmt.SetNumberingType(SVX_NUM_CHAR_SPECIAL);
1352                 // #i93908# clear suffix for bullet lists
1353                 aFmt.SetPrefix(::rtl::OUString());
1354                 aFmt.SetSuffix(::rtl::OUString());
1355             }
1356 
1357             // --> OD 2009-08-26 #i95907#
1358             if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
1359             {
1360                 if(bHtml && nLvl)
1361                 {
1362                     // 1/2" fuer HTML
1363                     aFmt.SetLSpace(720);
1364                     aFmt.SetAbsLSpace(nLvl * 720);
1365                 }
1366                 else if ( nWidthOfTabs > 0 )
1367                 {
1368                     aFmt.SetAbsLSpace(nWidthOfTabs + nLvl * 720);
1369                 }
1370             }
1371             // <--
1372 
1373             // --> FME 2005-01-21 #i38904#  Default alignment for
1374             // numbering/bullet should be rtl in rtl paragraph:
1375             if ( bRightToLeft )
1376             {
1377                 aFmt.SetNumAdjust( SVX_ADJUST_RIGHT );
1378             }
1379             // <--
1380 
1381             aNumRule.Set( nLvl, aFmt );
1382         }
1383 
1384         // --> OD 2009-08-26 #i95907#
1385         if ( pTxtNode &&
1386              ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT )
1387         {
1388             // --> OD 2010-01-05 #b6884103#
1389 //            short nTxtNodeFirstLineOffset( 0 );
1390 //            pTxtNode->GetFirstLineOfsWithNum( nTxtNodeFirstLineOffset );
1391 //            const SwTwips nTxtNodeIndent = pTxtNode->GetLeftMarginForTabCalculation() +
1392 //                                           nTxtNodeFirstLineOffset;
1393             const SwTwips nTxtNodeIndent = pTxtNode->GetAdditionalIndentForStartingNewList();
1394             // <--
1395             if ( ( nTxtNodeIndent + nWidthOfTabs ) != 0 )
1396             {
1397                 // --> OD 2010-05-05 #i111172#
1398                 // If text node is already inside a list, assure that the indents
1399                 // are the same. Thus, adjust the indent change value by subtracting
1400                 // indents of to be applied list style.
1401                 SwTwips nIndentChange = nTxtNodeIndent + nWidthOfTabs;
1402                 if ( pTxtNode->GetNumRule() )
1403                 {
1404                     const SwNumFmt aFmt( aNumRule.Get( 0 ) );
1405                     if ( aFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
1406                     {
1407                         nIndentChange -= aFmt.GetIndentAt() + aFmt.GetFirstLineIndent();
1408                     }
1409                 }
1410                 // <--
1411                 aNumRule.ChangeIndent( nIndentChange );
1412             }
1413         }
1414         // <--
1415         // --> OD 2008-02-08 #newlistlevelattrs#
1416         // reset indent attribute on applying list style
1417         // --> OD 2008-03-17 #refactorlists#
1418         // start new list
1419         SetCurNumRule( aNumRule, true, String(), true );
1420         // <--
1421     }
1422 
1423     EndUndo(UNDO_NUMORNONUM);
1424 }
1425 // <- #i40041#
1426 
NumOn()1427 void SwWrtShell::NumOn()
1428 {
1429     NumOrBulletOn(sal_True);
1430 }
1431 
NumOrBulletOff()1432 void SwWrtShell::NumOrBulletOff()
1433 {
1434     const SwNumRule * pCurNumRule = GetNumRuleAtCurrCrsrPos();
1435 
1436     if (pCurNumRule)
1437     {
1438         if (pCurNumRule->IsOutlineRule())
1439         {
1440             SwNumRule aNumRule(*pCurNumRule);
1441 
1442             SwTxtNode * pTxtNode =
1443                 GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
1444 
1445             if (pTxtNode)
1446             {
1447                 sal_uInt16 nLevel = sal::static_int_cast<sal_uInt16, sal_Int32>(pTxtNode->GetActualListLevel());
1448                 SwNumFmt aFmt(aNumRule.Get(nLevel));
1449 
1450                 aFmt.SetNumberingType(SVX_NUM_NUMBER_NONE);
1451                 aNumRule.Set(nLevel, aFmt);
1452 
1453                 // --> OD 2008-03-17 #refactorlists#
1454                 // no start or continuation of a list - the outline style is only changed.
1455                 SetCurNumRule( aNumRule, false );
1456                 // <--
1457             }
1458         }
1459         else
1460         {
1461             DelNumRules();
1462         }
1463 
1464         // --> OD 2005-10-24 #126346# - Cursor can not be anymore in front of
1465         // a label, because numbering/bullet is switched off.
1466         SetInFrontOfLabel( sal_False );
1467         // <--
1468     }
1469 }
1470 // <- #i29560#
1471 
1472 /*------------------------------------------------------------------------
1473  Beschreibung:  Default-Bulletliste erfragen
1474 ------------------------------------------------------------------------*/
1475 
BulletOn()1476 void SwWrtShell::BulletOn()
1477 {
1478     NumOrBulletOn(sal_False);
1479 }
1480 
1481 
1482 /*--------------------------------------------------
1483 
1484 --------------------------------------------------*/
GetSelectionType() const1485 SelectionType SwWrtShell::GetSelectionType() const
1486 {
1487     // ContentType kann nicht ermittelt werden innerhalb einer
1488     // Start-/Endactionklammerung.
1489     // Da es keinen ungültigen Wert gibt, wird TEXT geliefert.
1490     // Der Wert ist egal, da in EndAction ohnehin aktualisiert wird.
1491 
1492     if ( BasicActionPend() )
1493         return IsSelFrmMode() ? nsSelectionType::SEL_FRM : nsSelectionType::SEL_TXT;
1494 
1495     SwView &_rView = ((SwView&)GetView());
1496     if (_rView.GetPostItMgr() && _rView.GetPostItMgr()->HasActiveSidebarWin() )
1497         return nsSelectionType::SEL_POSTIT;
1498 
1499     int nCnt;
1500     // Insertion of a text frame is not a DrawMode
1501     if ( !_rView.GetEditWin().IsFrmAction() &&
1502         (IsObjSelected() || (_rView.IsDrawMode() && !IsFrmSelected()) ))
1503     {
1504         if (GetDrawView()->IsTextEdit())
1505             nCnt = nsSelectionType::SEL_DRW_TXT;
1506         else
1507         {
1508             if (GetView().IsFormMode()) // Nur Forms selektiert
1509                 nCnt = nsSelectionType::SEL_DRW_FORM;
1510             else
1511                 nCnt = nsSelectionType::SEL_DRW;            // Irgendein Draw-Objekt
1512 
1513             if (_rView.IsBezierEditMode())
1514                 nCnt |= nsSelectionType::SEL_BEZ;
1515             else if( GetDrawView()->GetContext() == SDRCONTEXT_MEDIA )
1516                 nCnt |= nsSelectionType::SEL_MEDIA;
1517 
1518             if (svx::checkForSelectedCustomShapes(
1519                 const_cast<SdrView *>(GetDrawView()),
1520                 true /* bOnlyExtruded */ ))
1521             {
1522                 nCnt |= nsSelectionType::SEL_EXTRUDED_CUSTOMSHAPE;
1523             }
1524             sal_uInt32 nCheckStatus = 0;
1525             if (svx::checkForSelectedFontWork(
1526                 const_cast<SdrView *>(GetDrawView()), nCheckStatus ))
1527             {
1528                 nCnt |= nsSelectionType::SEL_FONTWORK;
1529             }
1530         }
1531 
1532         return nCnt;
1533     }
1534 
1535     nCnt = GetCntType();
1536 
1537     if ( IsFrmSelected() )
1538     {
1539         if (_rView.IsDrawMode())
1540             _rView.LeaveDrawCreate();   // Aufräumen (Bug #45639)
1541         if ( !(nCnt & (CNT_GRF | CNT_OLE)) )
1542             return nsSelectionType::SEL_FRM;
1543     }
1544 
1545     if ( IsCrsrInTbl() )
1546         nCnt |= nsSelectionType::SEL_TBL;
1547 
1548     if ( IsTableMode() )
1549         nCnt |= (nsSelectionType::SEL_TBL | nsSelectionType::SEL_TBL_CELLS);
1550 
1551     // Do not pop up numbering toolbar, if the text node has a numbering of type SVX_NUM_NUMBER_NONE.
1552     const SwNumRule* pNumRule = GetNumRuleAtCurrCrsrPos();
1553     if ( pNumRule )
1554     {
1555         const SwTxtNode* pTxtNd =
1556             GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
1557 
1558         if ( pTxtNd && pTxtNd->IsInList() )
1559         {
1560             const SwNumFmt& rFmt = pNumRule->Get(sal::static_int_cast< sal_uInt8, sal_Int32>(pTxtNd->GetActualListLevel()));
1561             if ( SVX_NUM_NUMBER_NONE != rFmt.GetNumberingType() )
1562                 nCnt |= nsSelectionType::SEL_NUM;
1563         }
1564     }
1565 
1566     return nCnt;
1567 }
1568 
1569 /*------------------------------------------------------------------------
1570  Beschreibung:  Finden der TextCollection mit dem Name rCollname
1571  Return:                Pointer auf die Collection oder 0, wenn keine
1572                                 TextCollection mit diesem Namen existiert oder
1573                                 diese eine Defaultvorlage ist.
1574 ------------------------------------------------------------------------*/
1575 
1576 
GetParaStyle(const String & rCollName,GetStyle eCreate)1577 SwTxtFmtColl *SwWrtShell::GetParaStyle(const String &rCollName, GetStyle eCreate )
1578 {
1579     SwTxtFmtColl* pColl = FindTxtFmtCollByName( rCollName );
1580     if( !pColl && GETSTYLE_NOCREATE != eCreate )
1581     {
1582         sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( rCollName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
1583         if( USHRT_MAX != nId || GETSTYLE_CREATEANY == eCreate )
1584             pColl = GetTxtCollFromPool( nId );
1585     }
1586     return pColl;
1587 }
1588 /*------------------------------------------------------------------------
1589  Beschreibung:  Finden der Zeichenvorlage mit dem Name rCollname
1590  Return:                Pointer auf die Collection oder 0, wenn keine
1591                                 Zeichenvorlage mit diesem Namen existiert oder
1592                                 diese eine Defaultvorlage oder automatische Vorlage ist.
1593 ------------------------------------------------------------------------*/
1594 
1595 
1596 
GetCharStyle(const String & rFmtName,GetStyle eCreate)1597 SwCharFmt *SwWrtShell::GetCharStyle(const String &rFmtName, GetStyle eCreate )
1598 {
1599     SwCharFmt* pFmt = FindCharFmtByName( rFmtName );
1600     if( !pFmt && GETSTYLE_NOCREATE != eCreate )
1601     {
1602         sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( rFmtName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
1603         if( USHRT_MAX != nId || GETSTYLE_CREATEANY == eCreate )
1604             pFmt = (SwCharFmt*)GetFmtFromPool( nId );
1605     }
1606     return pFmt;
1607 }
1608 
1609 /*------------------------------------------------------------------------
1610  Beschreibung:  Finden des Tabellenformates mit dem Name rFmtname
1611  Return:                Pointer auf das Format oder 0, wenn kein
1612                                 Rahmenformat mit diesem Namen existiert oder
1613                                 dieses eine Defaultformat oder automatisches Format ist.
1614 ------------------------------------------------------------------------*/
1615 
1616 
1617 
GetTblStyle(const String & rFmtName)1618 SwFrmFmt *SwWrtShell::GetTblStyle(const String &rFmtName)
1619 {
1620     SwFrmFmt *pFmt = 0;
1621     for( sal_uInt16 i = GetTblFrmFmtCount(); i; )
1622         if( !( pFmt = &GetTblFrmFmt( --i ) )->IsDefault() &&
1623             pFmt->GetName() == rFmtName && IsUsed( *pFmt ) )
1624             return pFmt;
1625     return 0;
1626 }
1627 
1628 
1629 /*------------------------------------------------------------------------
1630  Beschreibung:  Anwenden der Vorlagen
1631 ------------------------------------------------------------------------*/
1632 
1633 
1634 
SetPageStyle(const String & rCollName)1635 void SwWrtShell::SetPageStyle(const String &rCollName)
1636 {
1637     if( !SwCrsrShell::HasSelection() && !IsSelFrmMode() && !IsObjSelected() )
1638     {
1639         SwPageDesc* pDesc = FindPageDescByName( rCollName, sal_True );
1640         if( pDesc )
1641             ChgCurPageDesc( *pDesc );
1642     }
1643 }
1644 
1645 /*------------------------------------------------------------------------
1646  Beschreibung:  Zugriff Vorlagen
1647 ------------------------------------------------------------------------*/
1648 
1649 
1650 
GetCurPageStyle(const sal_Bool bCalcFrm) const1651 String SwWrtShell::GetCurPageStyle( const sal_Bool bCalcFrm ) const
1652 {
1653     return GetPageDesc(GetCurPageDesc( bCalcFrm )).GetName();
1654 }
1655 
1656 /*------------------------------------------------------------------------
1657  Beschreibung:  Aktuelle Vorlage anhand der geltenden Attribute ändern
1658 ------------------------------------------------------------------------*/
1659 
1660 
QuickUpdateStyle()1661 void SwWrtShell::QuickUpdateStyle()
1662 {
1663     SwTxtFmtColl *pColl = GetCurTxtFmtColl();
1664 
1665     // Standard kann nicht geändert werden
1666     if(pColl && !pColl->IsDefault())
1667     {
1668         FillByEx(pColl);
1669             // Vorlage auch anwenden, um harte Attributierung
1670             // zu entfernen
1671         SetTxtFmtColl(pColl);
1672     }
1673 }
1674 
1675 
AutoUpdatePara(SwTxtFmtColl * pColl,const SfxItemSet & rStyleSet)1676 void SwWrtShell::AutoUpdatePara(SwTxtFmtColl* pColl, const SfxItemSet& rStyleSet)
1677 {
1678     SfxItemSet aCoreSet( GetAttrPool(),
1679             RES_CHRATR_BEGIN,           RES_CHRATR_END - 1,
1680             RES_PARATR_BEGIN,           RES_PARATR_END - 1,
1681             RES_FRMATR_BEGIN,           RES_FRMATR_END - 1,
1682             SID_ATTR_TABSTOP_POS,       SID_ATTR_TABSTOP_POS,
1683             SID_ATTR_TABSTOP_DEFAULTS,  SID_ATTR_TABSTOP_DEFAULTS,
1684             SID_ATTR_TABSTOP_OFFSET,    SID_ATTR_TABSTOP_OFFSET,
1685             SID_ATTR_BORDER_INNER,      SID_ATTR_BORDER_INNER,
1686             SID_ATTR_PARA_MODEL,        SID_ATTR_PARA_KEEP,
1687             SID_ATTR_PARA_PAGENUM,      SID_ATTR_PARA_PAGENUM,
1688             0   );
1689     GetCurAttr( aCoreSet );
1690     sal_Bool bReset = sal_False;
1691     SfxItemIter aParaIter( aCoreSet );
1692     const SfxPoolItem* pParaItem = aParaIter.FirstItem();
1693     while( pParaItem )
1694     {
1695         if(!IsInvalidItem(pParaItem))
1696         {
1697             sal_uInt16 nWhich = pParaItem->Which();
1698             if(SFX_ITEM_SET == aCoreSet.GetItemState(nWhich) &&
1699                SFX_ITEM_SET == rStyleSet.GetItemState(nWhich))
1700             {
1701                 aCoreSet.ClearItem(nWhich);
1702                 bReset = sal_True;
1703             }
1704         }
1705         pParaItem = aParaIter.NextItem();
1706     }
1707     StartAction();
1708     if(bReset)
1709     {
1710         ResetAttr();
1711         SetAttrSet(aCoreSet);
1712     }
1713     pDoc->ChgFmt(*pColl, rStyleSet );
1714     EndAction();
1715 }
1716 
1717 /*-----------------12.03.97 12.24-------------------
1718 
1719 --------------------------------------------------*/
1720 
AutoUpdateFrame(SwFrmFmt * pFmt,const SfxItemSet & rStyleSet)1721 void SwWrtShell::AutoUpdateFrame( SwFrmFmt* pFmt, const SfxItemSet& rStyleSet )
1722 {
1723     StartAction();
1724 
1725     ResetFlyFrmAttr( 0, &rStyleSet );
1726     pFmt->SetFmtAttr( rStyleSet );
1727 
1728     EndAction();
1729 }
1730 
1731 
AutoCorrect(SvxAutoCorrect & rACorr,sal_Unicode cChar)1732 void SwWrtShell::AutoCorrect( SvxAutoCorrect& rACorr, sal_Unicode cChar )
1733 {
1734     ResetCursorStack();
1735     if(_CanInsert())
1736     {
1737         sal_Bool bStarted = sal_False;
1738         if(HasSelection())
1739         {
1740                 // nur hier klammern, da das normale Insert schon an der
1741                 // Editshell geklammert ist
1742             StartAllAction();
1743             StartUndo(UNDO_INSERT);
1744             bStarted = sal_True;
1745             DelRight();
1746         }
1747         SwEditShell::AutoCorrect( rACorr, IsInsMode(), cChar );
1748 
1749         if(bStarted)
1750         {
1751             EndAllAction();
1752             EndUndo(UNDO_INSERT);
1753         }
1754     }
1755 }
1756 
1757 
1758 /*
1759  * eine Art kontrollierter copy ctor
1760  */
1761 
SwWrtShell(SwWrtShell & rSh,Window * _pWin,SwView & rShell)1762 SwWrtShell::SwWrtShell( SwWrtShell& rSh, Window *_pWin, SwView &rShell )
1763     : SwFEShell( rSh, _pWin ),
1764      COMMON_INI_LIST
1765 {
1766     BITFLD_INI_LIST
1767     SET_CURR_SHELL( this );
1768 
1769     SetSfxViewShell( (SfxViewShell *)&rShell );
1770     SetFlyMacroLnk( LINK(this, SwWrtShell, ExecFlyMac) );
1771 
1772     // place the cursor on the first field...
1773     IFieldmark *pBM = NULL;
1774     if ( IsFormProtected() && ( pBM = GetFieldmarkAfter( ) ) !=NULL ) {
1775         GotoFieldmark(pBM);
1776     }
1777 }
1778 
1779 
1780 SwWrtShell::SwWrtShell( SwDoc& rDoc, Window *_pWin, SwView &rShell,
1781                         const SwViewOption *pViewOpt )
1782     : SwFEShell( rDoc, _pWin, pViewOpt),
1783       COMMON_INI_LIST
1784 {
1785     BITFLD_INI_LIST
1786     SET_CURR_SHELL( this );
1787     SetSfxViewShell( (SfxViewShell *)&rShell );
1788     SetFlyMacroLnk( LINK(this, SwWrtShell, ExecFlyMac) );
1789 }
1790 
1791 /*
1792  * ctor
1793  */
1794 
1795 
1796 
1797 SwWrtShell::~SwWrtShell()
1798 {
1799     SET_CURR_SHELL( this );
1800     while(IsModePushed())
1801         PopMode();
1802     while(PopCrsr(sal_False))
1803         ;
1804     SwTransferable::ClearSelection( *this );
1805 }
1806 
Pop(sal_Bool bOldCrsr)1807 sal_Bool SwWrtShell::Pop( sal_Bool bOldCrsr )
1808 {
1809     sal_Bool bRet = SwCrsrShell::Pop( bOldCrsr );
1810     if( bRet && IsSelection() )
1811     {
1812         fnSetCrsr = &SwWrtShell::SetCrsrKillSel;
1813         fnKillSel = &SwWrtShell::ResetSelect;
1814     }
1815     return bRet;
1816 }
1817 
1818 /*--------------------------------------------------------------------
1819     Beschreibung:
1820  --------------------------------------------------------------------*/
CanInsert()1821 bool SwWrtShell::CanInsert()
1822 {
1823     // #123922# The original expression looks sleek, but it is not. Using the mathematical or ('|')
1824     // instead of the logical one ('||') forces the compiler to evaluate all conditions to allow or-ing
1825     // them together (yes, he could do better). Using the logical or allows to return on the first
1826     // failing statement instead.
1827     //
1828     // return (!(IsSelFrmMode() | IsObjSelected() | (GetView().GetDrawFuncPtr() != NULL) | (GetView().GetPostItMgr()->GetActiveSidebarWin()!= NULL)));
1829 
1830     if(IsSelFrmMode())
1831     {
1832         return false;
1833     }
1834 
1835     if(IsObjSelected())
1836     {
1837         return false;
1838     }
1839 
1840     if(GetView().GetDrawFuncPtr())
1841     {
1842         return false;
1843     }
1844 
1845     if(GetView().GetPostItMgr()->GetActiveSidebarWin())
1846     {
1847         return false;
1848     }
1849 
1850     return true;
1851 }
1852 
1853 
1854 // --------------
ChgDBData(const SwDBData & aDBData)1855 void SwWrtShell::ChgDBData(const SwDBData& aDBData)
1856 {
1857     SwEditShell::ChgDBData(aDBData);
1858     //notify the db-beamer if available
1859     GetView().NotifyDBChanged();
1860 }
1861 
GetSelDescr() const1862 String SwWrtShell::GetSelDescr() const
1863 {
1864     String aResult;
1865 
1866     int nSelType = GetSelectionType();
1867     switch (nSelType)
1868     {
1869     case nsSelectionType::SEL_GRF:
1870         aResult = SW_RES(STR_GRAPHIC);
1871 
1872         break;
1873     case nsSelectionType::SEL_FRM:
1874         {
1875             const SwFrmFmt * pFrmFmt = GetCurFrmFmt();
1876 
1877             if (pFrmFmt)
1878                 aResult = pFrmFmt->GetDescription();
1879         }
1880         break;
1881     case nsSelectionType::SEL_DRW:
1882         {
1883             aResult = SW_RES(STR_DRAWING_OBJECTS);
1884         }
1885         break;
1886     default:
1887         if (0 != pDoc)
1888             aResult = GetCrsrDescr();
1889     }
1890 
1891     return aResult;
1892 }
1893 
ApplyViewOptions(const SwViewOption & rOpt)1894 void SwWrtShell::ApplyViewOptions( const SwViewOption &rOpt )
1895 {
1896     SwFEShell::ApplyViewOptions( rOpt );
1897     //#i115062# invalidate meta character slot
1898     GetView().GetViewFrame()->GetBindings().Invalidate( FN_VIEW_META_CHARS );
1899 }
1900 
1901 /* vim: set noet sw=4 ts=4: */
1902