LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/wrtsh - wrtsh2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 216 0.5 %
Date: 2013-07-09 Functions: 2 13 15.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      21             : #include <hintids.hxx>      // define ITEMIDs
      22             : #include <svl/macitem.hxx>
      23             : #include <sfx2/frame.hxx>
      24             : #include <vcl/msgbox.hxx>
      25             : #include <svl/urihelper.hxx>
      26             : #include <svl/eitem.hxx>
      27             : #include <svl/stritem.hxx>
      28             : #include <sfx2/docfile.hxx>
      29             : #include <sfx2/fcontnr.hxx>
      30             : #include <sfx2/dispatch.hxx>
      31             : #include <sfx2/linkmgr.hxx>
      32             : #include <fmtinfmt.hxx>
      33             : #include <frmatr.hxx>
      34             : #include <swtypes.hxx>      // SET_CURR_SHELL
      35             : #include <wrtsh.hxx>
      36             : #include <docsh.hxx>
      37             : #include <fldbas.hxx>       // Fields
      38             : #include <expfld.hxx>
      39             : #include <ddefld.hxx>
      40             : #include <docufld.hxx>
      41             : #include <reffld.hxx>
      42             : #include <swundo.hxx>
      43             : #include <doc.hxx>
      44             : #include <IDocumentUndoRedo.hxx>
      45             : #include <viewopt.hxx>      // SwViewOptions
      46             : #include <frmfmt.hxx>       // for UpdateTable
      47             : #include <swtable.hxx>      // for UpdateTable
      48             : #include <mdiexp.hxx>
      49             : #include <view.hxx>
      50             : #include <swevent.hxx>
      51             : #include <poolfmt.hxx>
      52             : #include <section.hxx>
      53             : #include <navicont.hxx>
      54             : #include <navipi.hxx>
      55             : #include <crsskip.hxx>
      56             : #include <txtinet.hxx>
      57             : #include <cmdid.h>
      58             : #include <wrtsh.hrc>
      59             : #include "swabstdlg.hxx"
      60             : #include "fldui.hrc"
      61             : #include <SwRewriter.hxx>
      62             : 
      63             : #include <com/sun/star/document/XDocumentProperties.hpp>
      64             : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
      65             : 
      66             : #include <xmloff/odffields.hxx>
      67             : 
      68           0 : void SwWrtShell::Insert(SwField &rFld, SwPaM *pCommentRange)
      69             : {
      70           0 :     ResetCursorStack();
      71           0 :     if(!CanInsert())
      72           0 :         return;
      73           0 :     StartAllAction();
      74             : 
      75           0 :     SwRewriter aRewriter;
      76           0 :     aRewriter.AddRule(UndoArg1, rFld.GetDescription());
      77             : 
      78           0 :     StartUndo(UNDO_INSERT, &aRewriter);
      79             : 
      80           0 :     if (pCommentRange && GetDoc())
      81             :     {
      82             :         // If an annotation field is inserted, take care of the relevant fieldmark.
      83           0 :         IDocumentMarkAccess* pMarksAccess = GetDoc()->getIDocumentMarkAccess();
      84           0 :         sw::mark::IFieldmark* pFieldmark = pMarksAccess->makeFieldBookmark(*pCommentRange, OUString(), ODF_COMMENTRANGE);
      85           0 :         ((SwPostItField&)rFld).SetName(pFieldmark->GetName());
      86             :     }
      87             : 
      88           0 :     bool bDeleted = false;
      89           0 :     if( HasSelection() )
      90             :     {
      91           0 :         bDeleted = DelRight() != 0;
      92             :     }
      93             : 
      94           0 :     SwEditShell::Insert2(rFld, bDeleted);
      95           0 :     EndUndo();
      96           0 :     EndAllAction();
      97             : }
      98             : 
      99             : // Start the field update
     100             : 
     101           0 : void SwWrtShell::UpdateInputFlds( SwInputFieldList* pLst, sal_Bool bOnlyInSel )
     102             : {
     103             :     // Go through the list of fields and updating
     104           0 :     SwInputFieldList* pTmp = pLst;
     105           0 :     if( !pTmp )
     106           0 :         pTmp = new SwInputFieldList( this );
     107             : 
     108           0 :     if (bOnlyInSel)
     109           0 :         pTmp->RemoveUnselectedFlds();
     110             : 
     111           0 :     const sal_uInt16 nCnt = pTmp->Count();
     112           0 :     if(nCnt)
     113             :     {
     114           0 :         pTmp->PushCrsr();
     115             : 
     116           0 :         sal_Bool bCancel = sal_False;
     117           0 :         OString aDlgPos;
     118           0 :         for( sal_uInt16 i = 0; i < nCnt && !bCancel; ++i )
     119             :         {
     120           0 :             pTmp->GotoFieldPos( i );
     121           0 :             SwField* pField = pTmp->GetField( i );
     122           0 :             if(pField->GetTyp()->Which() == RES_DROPDOWN)
     123           0 :                 bCancel = StartDropDownFldDlg( pField, sal_True, &aDlgPos );
     124             :             else
     125           0 :                 bCancel = StartInputFldDlg( pField, sal_True, 0, &aDlgPos);
     126             : 
     127             :             // Otherwise update error at multi-selection:
     128           0 :             pTmp->GetField( i )->GetTyp()->UpdateFlds();
     129             :         }
     130           0 :         pTmp->PopCrsr();
     131             :     }
     132             : 
     133           0 :     if( !pLst )
     134           0 :         delete pTmp;
     135           0 : }
     136             : 
     137             : // Start input dialog for a specific field
     138             : 
     139           0 : sal_Bool SwWrtShell::StartInputFldDlg( SwField* pFld, sal_Bool bNextButton,
     140             :                                     Window* pParentWin, OString* pWindowState )
     141             : {
     142             : 
     143           0 :     SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     144             :     OSL_ENSURE(pFact, "Dialogdiet fail!");
     145           0 :     AbstractFldInputDlg* pDlg = pFact->CreateFldInputDlg(pParentWin, *this, pFld, bNextButton);
     146             :     OSL_ENSURE(pDlg, "Dialogdiet fail!");
     147           0 :     if(pWindowState && !pWindowState->isEmpty())
     148           0 :         pDlg->SetWindowState(*pWindowState);
     149           0 :     sal_Bool bRet = RET_CANCEL == pDlg->Execute();
     150           0 :     if(pWindowState)
     151           0 :         *pWindowState = pDlg->GetWindowState();
     152             : 
     153           0 :     delete pDlg;
     154           0 :     GetWin()->Update();
     155           0 :     return bRet;
     156             : }
     157             : 
     158           0 : sal_Bool SwWrtShell::StartDropDownFldDlg(SwField* pFld, sal_Bool bNextButton, OString* pWindowState)
     159             : {
     160           0 :     SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     161             :     OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
     162             : 
     163           0 :     AbstractDropDownFieldDialog* pDlg = pFact->CreateDropDownFieldDialog(NULL, *this, pFld, bNextButton);
     164             :     OSL_ENSURE(pDlg, "Dialogdiet fail!");
     165           0 :     if(pWindowState && !pWindowState->isEmpty())
     166           0 :         pDlg->SetWindowState(*pWindowState);
     167           0 :     sal_uInt16 nRet = pDlg->Execute();
     168           0 :     if(pWindowState)
     169           0 :         *pWindowState = pDlg->GetWindowState();
     170           0 :     delete pDlg;
     171           0 :     sal_Bool bRet = RET_CANCEL == nRet;
     172           0 :     GetWin()->Update();
     173           0 :     if(RET_YES == nRet)
     174             :     {
     175           0 :         GetView().GetViewFrame()->GetDispatcher()->Execute(FN_EDIT_FIELD, SFX_CALLMODE_SYNCHRON);
     176             :     }
     177           0 :     return bRet;
     178             : }
     179             : 
     180             : // Insert directory - remove selection
     181             : 
     182           0 : void SwWrtShell::InsertTableOf(const SwTOXBase& rTOX, const SfxItemSet* pSet)
     183             : {
     184           0 :     if(!CanInsert())
     185           0 :         return;
     186             : 
     187           0 :     if(HasSelection())
     188           0 :         DelRight();
     189             : 
     190           0 :     SwEditShell::InsertTableOf(rTOX, pSet);
     191             : }
     192             : 
     193             : // Update directory - remove selection
     194             : 
     195           0 : sal_Bool SwWrtShell::UpdateTableOf(const SwTOXBase& rTOX, const SfxItemSet* pSet)
     196             : {
     197           0 :     sal_Bool bResult = sal_False;
     198             : 
     199           0 :     if(CanInsert())
     200             :     {
     201           0 :         bResult = SwEditShell::UpdateTableOf(rTOX, pSet);
     202             : 
     203           0 :         if (pSet == NULL)
     204             :         {
     205           0 :             SwDoc *const pDoc_ = GetDoc();
     206           0 :             if (pDoc_)
     207             :             {
     208           0 :                 pDoc_->GetIDocumentUndoRedo().DelAllUndoObj();
     209             :             }
     210             :         }
     211             :     }
     212             : 
     213           0 :     return bResult;
     214             : }
     215             : 
     216             : // handler for click on the field given as parameter.
     217             : // the cursor is positioned on the field.
     218             : 
     219             : 
     220           0 : void SwWrtShell::ClickToField( const SwField& rFld )
     221             : {
     222             :     // cross reference field must not be selected because it moves the cursor
     223           0 :     if (RES_GETREFFLD != rFld.GetTyp()->Which())
     224             :     {
     225           0 :         StartAllAction();
     226           0 :         Right( CRSR_SKIP_CHARS, true, 1, false ); // Select the field.
     227           0 :         NormalizePam();
     228           0 :         EndAllAction();
     229             :     }
     230             : 
     231           0 :     bIsInClickToEdit = true;
     232           0 :     switch( rFld.GetTyp()->Which() )
     233             :     {
     234             :     case RES_JUMPEDITFLD:
     235             :         {
     236           0 :             sal_uInt16 nSlotId = 0;
     237           0 :             switch( rFld.GetFormat() )
     238             :             {
     239             :             case JE_FMT_TABLE:
     240           0 :                 nSlotId = FN_INSERT_TABLE;
     241           0 :                 break;
     242             : 
     243             :             case JE_FMT_FRAME:
     244           0 :                 nSlotId = FN_INSERT_FRAME;
     245           0 :                 break;
     246             : 
     247           0 :             case JE_FMT_GRAPHIC:    nSlotId = SID_INSERT_GRAPHIC;       break;
     248           0 :             case JE_FMT_OLE:        nSlotId = SID_INSERT_OBJECT;        break;
     249             : 
     250             :             }
     251             : 
     252           0 :             if( nSlotId )
     253             :             {
     254           0 :                 StartUndo( UNDO_START );
     255             :                 //#97295# immediately select the right shell
     256           0 :                 GetView().StopShellTimer();
     257           0 :                 GetView().GetViewFrame()->GetDispatcher()->Execute( nSlotId,
     258           0 :                             SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD );
     259           0 :                 EndUndo( UNDO_END );
     260             :             }
     261             :         }
     262           0 :         break;
     263             : 
     264             :     case RES_MACROFLD:
     265             :         {
     266           0 :             const SwMacroField *pFld = (const SwMacroField*)&rFld;
     267           0 :             String sText( rFld.GetPar2() );
     268           0 :             String sRet( sText );
     269           0 :             ExecMacro( pFld->GetSvxMacro(), &sRet );
     270             : 
     271             :             // return value changed?
     272           0 :             if( sRet != sText )
     273             :             {
     274           0 :                 StartAllAction();
     275           0 :                 ((SwField&)rFld).SetPar2( sRet );
     276           0 :                 ((SwField&)rFld).GetTyp()->UpdateFlds();
     277           0 :                 EndAllAction();
     278           0 :             }
     279             :         }
     280           0 :         break;
     281             : 
     282             :     case RES_GETREFFLD:
     283           0 :         StartAllAction();
     284           0 :         SwCrsrShell::GotoRefMark( ((SwGetRefField&)rFld).GetSetRefName(),
     285           0 :                                     ((SwGetRefField&)rFld).GetSubType(),
     286           0 :                                     ((SwGetRefField&)rFld).GetSeqNo() );
     287           0 :         EndAllAction();
     288           0 :         break;
     289             : 
     290             :     case RES_INPUTFLD:
     291           0 :         StartInputFldDlg( (SwField*)&rFld, sal_False );
     292           0 :         break;
     293             : 
     294             :     case RES_SETEXPFLD:
     295           0 :         if( ((SwSetExpField&)rFld).GetInputFlag() )
     296           0 :             StartInputFldDlg( (SwField*)&rFld, sal_False );
     297           0 :         break;
     298             :     case RES_DROPDOWN :
     299           0 :         StartDropDownFldDlg( (SwField*)&rFld, sal_False );
     300           0 :     break;
     301             :     default:
     302             :         SAL_WARN_IF(rFld.IsClickable(), "sw", "unhandled clickable field!");
     303             :     }
     304             : 
     305           0 :     bIsInClickToEdit = false;
     306           0 : }
     307             : 
     308           0 : void SwWrtShell::ClickToINetAttr( const SwFmtINetFmt& rItem, sal_uInt16 nFilter )
     309             : {
     310           0 :     if( !rItem.GetValue().Len() )
     311           0 :         return ;
     312             : 
     313           0 :     bIsInClickToEdit = true;
     314             : 
     315             :     // At first run the possibly set ObjectSelect Macro
     316           0 :     const SvxMacro* pMac = rItem.GetMacro( SFX_EVENT_MOUSECLICK_OBJECT );
     317           0 :     if( pMac )
     318             :     {
     319           0 :         SwCallMouseEvent aCallEvent;
     320           0 :         aCallEvent.Set( &rItem );
     321           0 :         GetDoc()->CallEvent( SFX_EVENT_MOUSECLICK_OBJECT, aCallEvent, false );
     322             :     }
     323             : 
     324             :     // So that the implementation of templates is displayed immediately
     325           0 :     ::LoadURL( *this, rItem.GetValue(), nFilter, rItem.GetTargetFrame() );
     326           0 :     const SwTxtINetFmt* pTxtAttr = rItem.GetTxtINetFmt();
     327           0 :     if( pTxtAttr )
     328             :     {
     329           0 :         const_cast<SwTxtINetFmt*>(pTxtAttr)->SetVisited( true );
     330           0 :         const_cast<SwTxtINetFmt*>(pTxtAttr)->SetVisitedValid( true );
     331             :     }
     332             : 
     333           0 :     bIsInClickToEdit = false;
     334             : }
     335             : 
     336           0 : bool SwWrtShell::ClickToINetGrf( const Point& rDocPt, sal_uInt16 nFilter )
     337             : {
     338           0 :     bool bRet = false;
     339           0 :     String sURL;
     340           0 :     String sTargetFrameName;
     341           0 :     const SwFrmFmt* pFnd = IsURLGrfAtPos( rDocPt, &sURL, &sTargetFrameName );
     342           0 :     if( pFnd && sURL.Len() )
     343             :     {
     344           0 :         bRet = true;
     345             :         // At first run the possibly set ObjectSelect Macro
     346           0 :         const SvxMacro* pMac = &pFnd->GetMacro().GetMacro( SFX_EVENT_MOUSECLICK_OBJECT );
     347           0 :         if( pMac )
     348             :         {
     349           0 :             SwCallMouseEvent aCallEvent;
     350           0 :             aCallEvent.Set( EVENT_OBJECT_URLITEM, pFnd );
     351           0 :             GetDoc()->CallEvent( SFX_EVENT_MOUSECLICK_OBJECT, aCallEvent, false );
     352             :         }
     353             : 
     354           0 :         ::LoadURL(*this, sURL, nFilter, sTargetFrameName);
     355             :     }
     356           0 :     return bRet;
     357             : }
     358             : 
     359             : 
     360           0 : void LoadURL( ViewShell& rVSh, const OUString& rURL, sal_uInt16 nFilter,
     361             :               const OUString& rTargetFrameName )
     362             : {
     363             :     OSL_ENSURE( !rURL.isEmpty(), "what should be loaded here?" );
     364           0 :     if( rURL.isEmpty() )
     365           0 :         return ;
     366             : 
     367             :     // The shell could be 0 also!!!!!
     368           0 :     if ( !rVSh.ISA(SwCrsrShell) )
     369           0 :         return;
     370             : 
     371             :     //A CrsrShell is always a WrtShell
     372           0 :     SwWrtShell &rSh = (SwWrtShell&)rVSh;
     373             : 
     374           0 :     SwDocShell* pDShell = rSh.GetView().GetDocShell();
     375             :     OSL_ENSURE( pDShell, "No DocShell?!");
     376           0 :     OUString sTargetFrame(rTargetFrameName);
     377           0 :     if (sTargetFrame.isEmpty() && pDShell)
     378             :     {
     379             :         using namespace ::com::sun::star;
     380             :         uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
     381           0 :             pDShell->GetModel(), uno::UNO_QUERY_THROW);
     382             :         uno::Reference<document::XDocumentProperties> xDocProps
     383           0 :             = xDPS->getDocumentProperties();
     384           0 :         sTargetFrame = xDocProps->getDefaultTarget();
     385             :     }
     386             : 
     387           0 :     String sReferer;
     388           0 :     if( pDShell && pDShell->GetMedium() )
     389           0 :         sReferer = pDShell->GetMedium()->GetName();
     390           0 :     SfxViewFrame* pViewFrm = rSh.GetView().GetViewFrame();
     391           0 :     SfxFrameItem aView( SID_DOCFRAME, pViewFrm );
     392           0 :     SfxStringItem aName( SID_FILE_NAME, rURL );
     393           0 :     SfxStringItem aTargetFrameName( SID_TARGETNAME, sTargetFrame );
     394           0 :     SfxStringItem aReferer( SID_REFERER, sReferer );
     395             : 
     396           0 :     SfxBoolItem aNewView( SID_OPEN_NEW_VIEW, sal_False );
     397             :     //#39076# Silent can be removed accordingly to SFX.
     398           0 :     SfxBoolItem aBrowse( SID_BROWSE, sal_True );
     399             : 
     400           0 :     if( nFilter & URLLOAD_NEWVIEW )
     401           0 :         aTargetFrameName.SetValue( OUString("_blank") );
     402             : 
     403             :     const SfxPoolItem* aArr[] = {
     404             :                 &aName,
     405             :                 &aNewView, /*&aSilent,*/
     406             :                 &aReferer,
     407             :                 &aView, &aTargetFrameName,
     408             :                 &aBrowse,
     409             :                 0L
     410           0 :     };
     411             : 
     412             :     pViewFrm->GetDispatcher()->GetBindings()->Execute( SID_OPENDOC, aArr,
     413           0 :             SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD );
     414             : }
     415             : 
     416           0 : void SwWrtShell::NavigatorPaste( const NaviContentBookmark& rBkmk,
     417             :                                     const sal_uInt16 nAction )
     418             : {
     419           0 :     if( EXCHG_IN_ACTION_COPY == nAction )
     420             :     {
     421             :         // Insert
     422           0 :         String sURL = rBkmk.GetURL();
     423             :         // Is this is a jump within the current Doc?
     424           0 :         const SwDocShell* pDocShell = GetView().GetDocShell();
     425           0 :         if(pDocShell->HasName())
     426             :         {
     427           0 :             const String rName = pDocShell->GetMedium()->GetURLObject().GetURLNoMark();
     428             : 
     429           0 :             if(COMPARE_EQUAL == sURL.CompareTo(rName, rName.Len()))
     430           0 :                 sURL.Erase(0, rName.Len());
     431             :         }
     432           0 :         SwFmtINetFmt aFmt( sURL, aEmptyStr );
     433           0 :         InsertURL( aFmt, rBkmk.GetDescription() );
     434             :     }
     435             :     else
     436             :     {
     437           0 :         SwSectionData aSection( FILE_LINK_SECTION, GetUniqueSectionName( 0 ) );
     438           0 :         String aLinkFile( rBkmk.GetURL().GetToken(0, '#') );
     439           0 :         aLinkFile += sfx2::cTokenSeparator;
     440           0 :         aLinkFile += sfx2::cTokenSeparator;
     441           0 :         aLinkFile += rBkmk.GetURL().GetToken(1, '#');
     442           0 :         aSection.SetLinkFileName( aLinkFile );
     443           0 :         aSection.SetProtectFlag( true );
     444           0 :         const SwSection* pIns = InsertSection( aSection );
     445           0 :         if( EXCHG_IN_ACTION_MOVE == nAction && pIns )
     446             :         {
     447           0 :             aSection = SwSectionData(*pIns);
     448           0 :             aSection.SetLinkFileName( aEmptyStr );
     449           0 :             aSection.SetType( CONTENT_SECTION );
     450           0 :             aSection.SetProtectFlag( false );
     451             : 
     452             :             // the update of content from linked section at time delete
     453             :             // the undostack. Then the change of the section dont create
     454             :             // any undoobject. -  BUG 69145
     455           0 :             sal_Bool bDoesUndo = DoesUndo();
     456           0 :             SwUndoId nLastUndoId(UNDO_EMPTY);
     457           0 :             if (GetLastUndoInfo(0, & nLastUndoId))
     458             :             {
     459           0 :                 if (UNDO_INSSECTION != nLastUndoId)
     460             :                 {
     461           0 :                     DoUndo(false);
     462             :                 }
     463             :             }
     464           0 :             UpdateSection( GetSectionFmtPos( *pIns->GetFmt() ), aSection );
     465           0 :             DoUndo( bDoesUndo );
     466           0 :         }
     467             :     }
     468          99 : }
     469             : 
     470             : 
     471             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10