LCOV - code coverage report
Current view: top level - sw/source/core/uibase/shells - textfld.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 19 485 3.9 %
Date: 2014-04-11 Functions: 3 10 30.0 %
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             : #include <crsskip.hxx>
      21             : #include <hintids.hxx>
      22             : 
      23             : #include <sfx2/lnkbase.hxx>
      24             : #include <fmtfld.hxx>
      25             : #include <vcl/msgbox.hxx>
      26             : #include <svl/itempool.hxx>
      27             : #include <unotools/useroptions.hxx>
      28             : #include <svl/whiter.hxx>
      29             : #include <svl/eitem.hxx>
      30             : #include <svl/macitem.hxx>
      31             : #include <sfx2/viewfrm.hxx>
      32             : #include <sfx2/request.hxx>
      33             : #include <svx/postattr.hxx>
      34             : #include <svx/hlnkitem.hxx>
      35             : #include <svx/svxdlg.hxx>
      36             : #include <sfx2/linkmgr.hxx>
      37             : #include <unotools/localedatawrapper.hxx>
      38             : #include <sfx2/dispatch.hxx>
      39             : #include <fmtinfmt.hxx>
      40             : #include <fldwrap.hxx>
      41             : #include <redline.hxx>
      42             : #include <view.hxx>
      43             : #include <viewopt.hxx>
      44             : #include <wrtsh.hxx>
      45             : #include <basesh.hxx>
      46             : #include <flddat.hxx>
      47             : #include <numrule.hxx>
      48             : #include <textsh.hxx>
      49             : #include <docsh.hxx>
      50             : #include <docufld.hxx>
      51             : #include <usrfld.hxx>
      52             : #include <ddefld.hxx>
      53             : #include <expfld.hxx>
      54             : #include <fldmgr.hxx>
      55             : #include <uitool.hxx>
      56             : #include <cmdid.h>
      57             : #include <shells.hrc>
      58             : #include <sfx2/app.hxx>
      59             : #include <svx/dialogs.hrc>
      60             : #include "swabstdlg.hxx"
      61             : #include "dialog.hrc"
      62             : #include <fldui.hrc>
      63             : #include <doc.hxx>
      64             : #include <app.hrc>
      65             : #include <edtwin.hxx>
      66             : #include <PostItMgr.hxx>
      67             : #include <switerator.hxx>
      68             : 
      69             : using namespace nsSwDocInfoSubType;
      70             : 
      71             : extern bool bNoInterrupt;       // in mainwn.cxx
      72             : 
      73           0 : static OUString& lcl_AppendRedlineStr( OUString& rStr, sal_uInt16 nRedlId )
      74             : {
      75           0 :     sal_uInt16 nResId = 0;
      76           0 :     switch( nRedlId )
      77             :     {
      78           0 :     case nsRedlineType_t::REDLINE_INSERT:   nResId = STR_REDLINE_INSERTED;      break;
      79           0 :     case nsRedlineType_t::REDLINE_DELETE:   nResId = STR_REDLINE_DELETED;       break;
      80           0 :     case nsRedlineType_t::REDLINE_FORMAT:   nResId = STR_REDLINE_FORMATED;      break;
      81           0 :     case nsRedlineType_t::REDLINE_TABLE:        nResId = STR_REDLINE_TABLECHG;      break;
      82           0 :     case nsRedlineType_t::REDLINE_FMTCOLL:  nResId = STR_REDLINE_FMTCOLLSET;    break;
      83             :     }
      84           0 :     if( nResId )
      85           0 :         rStr += SW_RESSTR( nResId );
      86           0 :     return rStr;
      87             : }
      88             : 
      89           0 : void SwTextShell::ExecField(SfxRequest &rReq)
      90             : {
      91           0 :     SwWrtShell& rSh = GetShell();
      92           0 :     const SfxPoolItem* pItem = 0;
      93             : 
      94           0 :     sal_uInt16 nSlot = rReq.GetSlot();
      95           0 :     const SfxItemSet* pArgs = rReq.GetArgs();
      96           0 :     if(pArgs)
      97           0 :         pArgs->GetItemState(GetPool().GetWhich(nSlot), false, &pItem);
      98             : 
      99           0 :     Window *pMDI = &GetView().GetViewFrame()->GetWindow();
     100           0 :     bool bMore = false;
     101           0 :     bool bIsText = true;
     102           0 :     sal_uInt16 nInsertType = 0;
     103           0 :     sal_uInt16 nInsertSubType = 0;
     104           0 :     sal_uLong nInsertFormat = 0;
     105             : 
     106           0 :     switch(nSlot)
     107             :     {
     108             :         case FN_EDIT_FIELD:
     109             :         {
     110           0 :             SwField* pFld = rSh.GetCurFld();
     111           0 :             if( pFld )
     112             :             {
     113           0 :                 switch ( pFld->GetTypeId() )
     114             :                 {
     115             :                     case TYP_DDEFLD:
     116             :                     {
     117           0 :                         ::sfx2::SvBaseLink& rLink = ((SwDDEFieldType*)pFld->GetTyp())->
     118           0 :                                                 GetBaseLink();
     119           0 :                         if(rLink.IsVisible())
     120             :                         {
     121           0 :                             SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     122           0 :                             SfxAbstractLinksDialog* pDlg = pFact->CreateLinksDialog( pMDI, &rSh.GetLinkManager(), false, &rLink );
     123           0 :                             if ( pDlg )
     124             :                             {
     125           0 :                                 pDlg->Execute();
     126           0 :                                 delete pDlg;
     127             :                             }
     128             :                         }
     129           0 :                         break;
     130             :                     }
     131             :                     default:
     132             :                     {
     133           0 :                         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     134             :                         OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
     135             : 
     136           0 :                         SfxAbstractDialog* pDlg = pFact->CreateSwFldEditDlg( GetView(),RC_DLG_SWFLDEDITDLG );
     137             :                         OSL_ENSURE(pDlg, "Dialogdiet fail!");
     138           0 :                         pDlg->Execute();
     139           0 :                         delete pDlg;
     140             :                     }
     141             :                 }
     142             :             }
     143           0 :             break;
     144             :         }
     145             :         case FN_EXECUTE_MACROFIELD:
     146             :         {
     147           0 :             SwField* pFld = rSh.GetCurFld();
     148           0 :             if(pFld && pFld->GetTyp()->Which() == RES_MACROFLD)
     149             :             {
     150             : 
     151           0 :                 const OUString& rMacro = ((SwMacroField*)pFld)->GetMacro();
     152           0 :                 sal_Int32 nPos = rMacro.indexOf('.');
     153           0 :                 if(nPos != -1)
     154             :                 {
     155           0 :                     SvxMacro aMacro( rMacro.copy(nPos + 1), rMacro.copy(0,nPos), STARBASIC );
     156           0 :                     rSh.ExecMacro(aMacro);
     157           0 :                 }
     158             :             }
     159             :         }
     160           0 :         break;
     161             : 
     162             :         case FN_GOTO_NEXT_INPUTFLD:
     163             :         case FN_GOTO_PREV_INPUTFLD:
     164             :             {
     165           0 :                 sal_Bool bRet = sal_False;
     166           0 :                 SwFieldType* pFld = rSh.GetFldType( 0, RES_INPUTFLD );
     167           0 :                 const bool bAddSetExpressionFlds = !( rSh.GetViewOptions()->IsReadonly() );
     168           0 :                 if ( pFld != NULL
     169           0 :                      && rSh.MoveFldType(
     170             :                             pFld,
     171             :                             FN_GOTO_NEXT_INPUTFLD == nSlot,
     172             :                             USHRT_MAX,
     173           0 :                             bAddSetExpressionFlds ) )
     174             :                 {
     175           0 :                     rSh.ClearMark();
     176           0 :                     if ( dynamic_cast<SwInputField*>(rSh.GetCurFld( true )) != NULL )
     177             :                     {
     178           0 :                         rSh.SttSelect();
     179             :                         rSh.SelectTxt(
     180           0 :                             rSh.StartOfInputFldAtPos( *(rSh.GetCrsr()->Start()) ) + 1,
     181           0 :                             rSh.EndOfInputFldAtPos( *(rSh.GetCrsr()->Start()) ) - 1 );
     182             :                     }
     183             :                     else
     184             :                     {
     185           0 :                         rSh.StartInputFldDlg( rSh.GetCurFld( true ), sal_False );
     186             :                     }
     187           0 :                     bRet = sal_True;
     188             :                 }
     189             : 
     190           0 :                 rReq.SetReturnValue( SfxBoolItem( nSlot, bRet ));
     191             :             }
     192           0 :             break;
     193             : 
     194             :         default:
     195           0 :             bMore = true;
     196             :     }
     197           0 :     if(bMore)
     198             :     {
     199             :         // Here come the slots with FldMgr.
     200           0 :         SwFldMgr aFldMgr(GetShellPtr());
     201           0 :         switch(nSlot)
     202             :         {
     203             :             case FN_INSERT_DBFIELD:
     204             :             {
     205           0 :                 sal_Bool bRes = sal_False;
     206           0 :                 if( pItem )
     207             :                 {
     208           0 :                     sal_uLong  nFormat = 0;
     209           0 :                     sal_uInt16 nType = 0;
     210           0 :                     OUString aPar1 = ((SfxStringItem *)pItem)->GetValue();
     211           0 :                     OUString aPar2;
     212           0 :                     sal_Int32 nCommand = 0;
     213             : 
     214           0 :                     if( SFX_ITEM_SET == pArgs->GetItemState( FN_PARAM_FIELD_TYPE,
     215           0 :                                                                 false, &pItem ))
     216           0 :                         nType = ((SfxUInt16Item *)pItem)->GetValue();
     217           0 :                     aPar1 += OUString(DB_DELIM);
     218           0 :                     if( SFX_ITEM_SET == pArgs->GetItemState(
     219           0 :                                         FN_PARAM_1, false, &pItem ))
     220             :                     {
     221           0 :                         aPar1 += ((SfxStringItem *)pItem)->GetValue();
     222             :                     }
     223           0 :                     if( SFX_ITEM_SET == pArgs->GetItemState(
     224           0 :                                         FN_PARAM_3, false, &pItem ))
     225           0 :                         nCommand = ((SfxInt32Item*)pItem)->GetValue();
     226           0 :                     aPar1 += OUString(DB_DELIM);
     227           0 :                     aPar1 += OUString::number(nCommand);
     228           0 :                     aPar1 += OUString(DB_DELIM);
     229           0 :                     if( SFX_ITEM_SET == pArgs->GetItemState(
     230           0 :                                         FN_PARAM_2, false, &pItem ))
     231             :                     {
     232           0 :                         aPar1 += ((SfxStringItem *)pItem)->GetValue();
     233             :                     }
     234           0 :                     if( SFX_ITEM_SET == pArgs->GetItemState(
     235           0 :                                         FN_PARAM_FIELD_CONTENT, false, &pItem ))
     236           0 :                         aPar2 = ((SfxStringItem *)pItem)->GetValue();
     237           0 :                     if( SFX_ITEM_SET == pArgs->GetItemState(
     238           0 :                                         FN_PARAM_FIELD_FORMAT, false, &pItem ))
     239           0 :                         nFormat = ((SfxUInt32Item *)pItem)->GetValue();
     240             :                     OSL_FAIL("Command is not yet used");
     241           0 :                     sal_Unicode cSeparator = ' ';
     242           0 :                     SwInsertFld_Data aData(nType, 0, aPar1, aPar2, nFormat, GetShellPtr(), cSeparator );
     243           0 :                     bRes = aFldMgr.InsertFld(aData);
     244             :                 }
     245           0 :                 rReq.SetReturnValue(SfxBoolItem( nSlot, bRes ));
     246             :             }
     247           0 :             break;
     248             :             case FN_INSERT_FIELD_CTRL:
     249             :             case FN_INSERT_FIELD:
     250             :             {
     251           0 :                 sal_Bool bRes = sal_False;
     252           0 :                 if( pItem && nSlot != FN_INSERT_FIELD_CTRL)
     253             :                 {
     254           0 :                     sal_uLong  nFormat = 0;
     255           0 :                     sal_uInt16 nType = 0;
     256           0 :                     sal_uInt16 nSubType = 0;
     257           0 :                     OUString aPar1 = ((SfxStringItem *)pItem)->GetValue();
     258           0 :                     OUString aPar2;
     259           0 :                     sal_Unicode cSeparator = ' ';
     260             : 
     261           0 :                     if( SFX_ITEM_SET == pArgs->GetItemState( FN_PARAM_FIELD_TYPE,
     262           0 :                                                                 false, &pItem ))
     263           0 :                         nType = ((SfxUInt16Item *)pItem)->GetValue();
     264           0 :                     if( SFX_ITEM_SET == pArgs->GetItemState( FN_PARAM_FIELD_SUBTYPE,
     265           0 :                                                                 false, &pItem ))
     266           0 :                         nSubType = ((SfxUInt16Item *)pItem)->GetValue();
     267           0 :                     if( SFX_ITEM_SET == pArgs->GetItemState(
     268           0 :                                         FN_PARAM_FIELD_CONTENT, false, &pItem ))
     269           0 :                         aPar2 = ((SfxStringItem *)pItem)->GetValue();
     270           0 :                     if( SFX_ITEM_SET == pArgs->GetItemState(
     271           0 :                                         FN_PARAM_FIELD_FORMAT, false, &pItem ))
     272           0 :                         nFormat = ((SfxUInt32Item *)pItem)->GetValue();
     273           0 :                     if( SFX_ITEM_SET == pArgs->GetItemState(
     274           0 :                                         FN_PARAM_3, false, &pItem ))
     275             :                     {
     276           0 :                         OUString sTmp = ((SfxStringItem *)pItem)->GetValue();
     277           0 :                         if(!sTmp.isEmpty())
     278           0 :                             cSeparator = sTmp[0];
     279             :                     }
     280           0 :                     SwInsertFld_Data aData(nType, nSubType, aPar1, aPar2, nFormat, GetShellPtr(), cSeparator );
     281           0 :                     bRes = aFldMgr.InsertFld( aData );
     282             :                 }
     283             :                 else
     284             :                         //#i5788# prevent closing of the field dialog while a modal dialog ( Input field dialog ) is active
     285           0 :                         if(!GetView().GetViewFrame()->IsInModalMode())
     286             :                 {
     287           0 :                     SfxViewFrame* pVFrame = GetView().GetViewFrame();
     288           0 :                     pVFrame->ToggleChildWindow(FN_INSERT_FIELD);
     289           0 :                     bRes = pVFrame->GetChildWindow( nSlot ) != 0;
     290           0 :                     Invalidate(rReq.GetSlot());
     291           0 :                     Invalidate(FN_INSERT_FIELD_CTRL);
     292           0 :                     rReq.Ignore();
     293             :                 }
     294           0 :                 rReq.SetReturnValue(SfxBoolItem( nSlot, bRes ));
     295             :             }
     296           0 :             break;
     297             : 
     298             :             case FN_INSERT_REF_FIELD:
     299             :             {
     300           0 :                 SfxViewFrame* pVFrame = GetView().GetViewFrame();
     301           0 :                 if (!pVFrame->HasChildWindow(FN_INSERT_FIELD))
     302           0 :                     pVFrame->ToggleChildWindow(FN_INSERT_FIELD);    // Show dialog
     303             : 
     304             :                 // Switch Flddlg at a new TabPage
     305           0 :                 sal_uInt16 nId = SwFldDlgWrapper::GetChildWindowId();
     306           0 :                 SwFldDlgWrapper *pWrp = (SwFldDlgWrapper*)pVFrame->GetChildWindow(nId);
     307           0 :                 if (pWrp)
     308           0 :                     pWrp->ShowReferencePage();
     309           0 :                 rReq.Ignore();
     310             :             }
     311           0 :             break;
     312             :             case FN_DELETE_COMMENT:
     313           0 :                 if ( GetView().GetPostItMgr() &&
     314           0 :                      GetView().GetPostItMgr()->HasActiveSidebarWin() )
     315             :                 {
     316           0 :                     GetView().GetPostItMgr()->DeleteActiveSidebarWin();
     317             :                 }
     318           0 :             break;
     319             :             case FN_DELETE_ALL_NOTES:
     320           0 :                 if ( GetView().GetPostItMgr() )
     321           0 :                     GetView().GetPostItMgr()->Delete();
     322           0 :             break;
     323             :             case FN_DELETE_NOTE_AUTHOR:
     324             :             {
     325           0 :                 SFX_REQUEST_ARG( rReq, pNoteItem, SfxStringItem, nSlot, false);
     326           0 :                 if ( pNoteItem && GetView().GetPostItMgr() )
     327           0 :                     GetView().GetPostItMgr()->Delete( pNoteItem->GetValue() );
     328             :             }
     329           0 :             break;
     330             :             case FN_HIDE_NOTE:
     331           0 :                 if ( GetView().GetPostItMgr() &&
     332           0 :                      GetView().GetPostItMgr()->HasActiveSidebarWin() )
     333             :                 {
     334           0 :                     GetView().GetPostItMgr()->HideActiveSidebarWin();
     335             :                 }
     336           0 :             break;
     337             :             case FN_HIDE_ALL_NOTES:
     338           0 :                 if ( GetView().GetPostItMgr() )
     339           0 :                     GetView().GetPostItMgr()->Hide();
     340           0 :             break;
     341             :             case FN_HIDE_NOTE_AUTHOR:
     342             :             {
     343           0 :                 SFX_REQUEST_ARG( rReq, pNoteItem, SfxStringItem, nSlot, false);
     344           0 :                 if ( pNoteItem && GetView().GetPostItMgr() )
     345           0 :                     GetView().GetPostItMgr()->Hide( pNoteItem->GetValue() );
     346             :             }
     347           0 :             break;
     348             :             case FN_POSTIT:
     349             :             {
     350           0 :                 SwPostItField* pPostIt = dynamic_cast<SwPostItField*>(aFldMgr.GetCurFld());
     351           0 :                 bool bNew = !(pPostIt && pPostIt->GetTyp()->Which() == RES_POSTITFLD);
     352           0 :                 if (bNew || GetView().GetPostItMgr()->IsAnswer())
     353             :                 {
     354           0 :                     SvtUserOptions aUserOpt;
     355           0 :                     OUString sAuthor;
     356           0 :                     if( (sAuthor = aUserOpt.GetFullName()).isEmpty())
     357           0 :                         if( (sAuthor = aUserOpt.GetID()).isEmpty() )
     358           0 :                             sAuthor = SW_RES( STR_REDLINE_UNKNOWN_AUTHOR );
     359             : 
     360           0 :                     if ( rSh.HasSelection() && !rSh.IsTableMode() )
     361             :                     {
     362           0 :                         rSh.KillPams();
     363             :                     }
     364             : 
     365             :                     // #i120513# Inserting a comment into an autocompletion crashes
     366             :                     // --> suggestion has to be removed before
     367           0 :                     GetView().GetEditWin().StopQuickHelp();
     368             : 
     369           0 :                     SwInsertFld_Data aData(TYP_POSTITFLD, 0, sAuthor, OUString(), 0);
     370           0 :                     aFldMgr.InsertFld( aData );
     371             : 
     372           0 :                     rSh.Push();
     373           0 :                     rSh.SwCrsrShell::Left(1, CRSR_SKIP_CHARS, sal_False);
     374           0 :                     pPostIt = (SwPostItField*)aFldMgr.GetCurFld();
     375           0 :                     rSh.Pop(sal_False); // Restore cursor position
     376             :                  }
     377             : 
     378           0 :                 if (pPostIt)
     379             :                 {
     380           0 :                     SwFieldType* pType = rSh.GetDoc()->GetFldType(RES_POSTITFLD, OUString(), false);
     381           0 :                     SwIterator<SwFmtFld,SwFieldType> aIter( *pType );
     382           0 :                     SwFmtFld* pSwFmtFld = aIter.First();
     383           0 :                     while( pSwFmtFld )
     384             :                     {
     385           0 :                         if ( pSwFmtFld->GetField() == pPostIt )
     386             :                         {
     387           0 :                             pSwFmtFld->Broadcast( SwFmtFldHint( 0, SWFMTFLD_FOCUS, &GetView() ) );
     388           0 :                             break;
     389             :                         }
     390           0 :                         pSwFmtFld = aIter.Next();
     391           0 :                     }
     392             :                 }
     393             :             }
     394           0 :             break;
     395             :             case FN_REDLINE_COMMENT:
     396             :             {
     397             :                 /*  this code can be used once we want redline comments in the margin, all other stuff can
     398             :                     then be deleted
     399             :                 String sComment;
     400             :                 const SwRangeRedline *pRedline = rSh.GetCurrRedline();
     401             : 
     402             :                 if (pRedline)
     403             :                 {
     404             :                     sComment = pRedline->GetComment();
     405             :                     if ( !sComment.Len() )
     406             :                         GetView().GetDocShell()->Broadcast(SwRedlineHint(pRedline,SWREDLINE_INSERTED));
     407             :                     const_cast<SwRangeRedline*>(pRedline)->Broadcast(SwRedlineHint(pRedline,SWREDLINE_FOCUS,&GetView()));
     408             :                 }
     409             :                 */
     410             : 
     411           0 :                 const SwRangeRedline *pRedline = rSh.GetCurrRedline();
     412             : 
     413           0 :                 if (pRedline)
     414             :                 {
     415           0 :                     OUString sComment = convertLineEnd(pRedline->GetComment(), GetSystemLineEnd());
     416             : 
     417           0 :                     sal_Bool bTravel = sal_False;
     418             : 
     419           0 :                     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     420             :                     OSL_ENSURE(pFact, "Dialogdiet fail!");
     421           0 :                     ::DialogGetRanges fnGetRange = pFact->GetDialogGetRangesFunc();
     422             :                     OSL_ENSURE(fnGetRange, "Dialogdiet fail! GetRanges()");
     423           0 :                     SfxItemSet aSet(GetPool(), fnGetRange());
     424           0 :                     aSet.Put(SvxPostItTextItem(sComment, SID_ATTR_POSTIT_TEXT));
     425           0 :                     aSet.Put(SvxPostItAuthorItem(pRedline->GetAuthorString(), SID_ATTR_POSTIT_AUTHOR));
     426             : 
     427             :                     aSet.Put( SvxPostItDateItem( GetAppLangDateTimeString(
     428           0 :                                 pRedline->GetRedlineData().GetTimeStamp() ),
     429           0 :                                 SID_ATTR_POSTIT_DATE ));
     430             : 
     431             :                     // Traveling only if more than one field.
     432           0 :                     rSh.StartAction();
     433             : 
     434           0 :                     rSh.Push();
     435           0 :                     const SwRangeRedline *pActRed = rSh.SelPrevRedline();
     436             : 
     437           0 :                     if (pActRed == pRedline)
     438             :                     {   // New cursor is at the beginning of the current redlines.
     439           0 :                         rSh.Pop();  // Throw old cursor away
     440           0 :                         rSh.Push();
     441           0 :                         pActRed = rSh.SelPrevRedline();
     442             :                     }
     443             : 
     444           0 :                     sal_Bool bPrev = pActRed != 0;
     445           0 :                     rSh.Pop(sal_False);
     446           0 :                     rSh.EndAction();
     447             : 
     448           0 :                     rSh.ClearMark();
     449           0 :                     rSh.SelNextRedline();   // Select current redline.
     450             : 
     451           0 :                     rSh.StartAction();
     452           0 :                     rSh.Push();
     453           0 :                     pActRed = rSh.SelNextRedline();
     454           0 :                     sal_Bool bNext = pActRed != 0;
     455           0 :                     rSh.Pop(sal_False); // Restore cursor position
     456             : 
     457           0 :                     if( rSh.IsCrsrPtAtEnd() )
     458           0 :                         rSh.SwapPam();
     459             : 
     460           0 :                     rSh.EndAction();
     461             : 
     462           0 :                     bTravel |= bNext|bPrev;
     463             : 
     464           0 :                     SvxAbstractDialogFactory* pFact2 = SvxAbstractDialogFactory::Create();
     465             :                     OSL_ENSURE(pFact2, "Dialogdiet fail!");
     466           0 :                     AbstractSvxPostItDialog* pDlg = pFact2->CreateSvxPostItDialog( pMDI, aSet, bTravel );
     467             :                     OSL_ENSURE(pDlg, "Dialogdiet fail!");
     468           0 :                     pDlg->HideAuthor();
     469             : 
     470           0 :                     OUString sTitle(SW_RES(STR_REDLINE_COMMENT));
     471           0 :                     ::lcl_AppendRedlineStr( sTitle, pRedline->GetType() );
     472             : 
     473           0 :                     pDlg->SetText(sTitle);
     474             : 
     475           0 :                     if (bTravel)
     476             :                     {
     477           0 :                         pDlg->EnableTravel(bNext, bPrev);
     478           0 :                         pDlg->SetPrevHdl(LINK(this, SwTextShell, RedlinePrevHdl));
     479           0 :                         pDlg->SetNextHdl(LINK(this, SwTextShell, RedlineNextHdl));
     480             :                     }
     481             : 
     482           0 :                     rSh.SetCareWin(pDlg->GetWindow());
     483           0 :                     bNoInterrupt = true;
     484             : 
     485           0 :                     if ( pDlg->Execute() == RET_OK )
     486             :                     {
     487           0 :                         const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
     488           0 :                         OUString sMsg(((const SvxPostItTextItem&)pOutSet->Get(SID_ATTR_POSTIT_TEXT)).GetValue());
     489             : 
     490             :                         // Insert or change a comment
     491           0 :                         rSh.SetRedlineComment(sMsg);
     492             :                     }
     493             : 
     494           0 :                     delete pDlg;
     495           0 :                     rSh.SetCareWin(NULL);
     496           0 :                     bNoInterrupt = false;
     497           0 :                     rSh.ClearMark();
     498           0 :                     GetView().AttrChangedNotify(GetShellPtr());
     499             :                 }
     500             :             }
     501           0 :             break;
     502             : 
     503             :             case FN_JAVAEDIT:
     504             :             {
     505           0 :                 OUString aType, aText;
     506           0 :                 sal_Bool bIsUrl=sal_False;
     507           0 :                 sal_Bool bNew=sal_False;
     508           0 :                 bool bUpdate = false;
     509           0 :                 SwFldMgr aMgr;
     510           0 :                 if ( pItem )
     511             :                 {
     512           0 :                     aText = ((SfxStringItem*)pItem)->GetValue();
     513           0 :                     SFX_REQUEST_ARG( rReq, pType, SfxStringItem, FN_PARAM_2 , false );
     514           0 :                     SFX_REQUEST_ARG( rReq, pIsUrl, SfxBoolItem, FN_PARAM_1 , false );
     515           0 :                     if ( pType )
     516           0 :                         aType = pType->GetValue();
     517           0 :                     if ( pIsUrl )
     518           0 :                         bIsUrl = pIsUrl->GetValue();
     519             : 
     520           0 :                     SwScriptField* pFld = (SwScriptField*)aMgr.GetCurFld();
     521           0 :                     bNew = !pFld || !(pFld->GetTyp()->Which() == RES_SCRIPTFLD);
     522           0 :                     bUpdate = pFld && ( bIsUrl != pFld->GetFormat() || pFld->GetPar2() != aType || pFld->GetPar1() != aText );
     523             :                 }
     524             :                 else
     525             :                 {
     526           0 :                     SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     527             :                     OSL_ENSURE(pFact, "Dialogdiet fail!");
     528           0 :                     AbstractJavaEditDialog* pDlg = pFact->CreateJavaEditDialog(pMDI, &rSh);
     529             :                     OSL_ENSURE(pDlg, "Dialogdiet fail!");
     530           0 :                     if ( pDlg->Execute() )
     531             :                     {
     532           0 :                         aType = pDlg->GetScriptType();
     533           0 :                         aText = pDlg->GetScriptText();
     534           0 :                         bIsUrl = pDlg->IsUrl();
     535           0 :                         bNew = pDlg->IsNew();
     536           0 :                         bUpdate = pDlg->IsUpdate();
     537           0 :                         rReq.AppendItem( SfxStringItem( FN_JAVAEDIT, aText ) );
     538           0 :                         rReq.AppendItem( SfxStringItem( FN_PARAM_2, aType ) );
     539           0 :                         rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bIsUrl ) );
     540             :                     }
     541             : 
     542           0 :                     delete pDlg;
     543             :                 }
     544             : 
     545           0 :                 if( bNew )
     546             :                 {
     547           0 :                     SwInsertFld_Data aData(TYP_SCRIPTFLD, 0, aType, aText, bIsUrl);
     548           0 :                     aMgr.InsertFld(aData);
     549           0 :                     rReq.Done();
     550             :                 }
     551           0 :                 else if( bUpdate )
     552             :                 {
     553           0 :                     aMgr.UpdateCurFld( bIsUrl, aType, aText );
     554           0 :                     rSh.SetUndoNoResetModified();
     555           0 :                     rReq.Done();
     556             :                 }
     557             :                 else
     558           0 :                     rReq.Ignore();
     559             :             }
     560           0 :             break;
     561             : 
     562             :             case FN_INSERT_FLD_DATE    :
     563           0 :                 nInsertType = TYP_DATEFLD;
     564           0 :                 bIsText = false;
     565           0 :                 goto FIELD_INSERT;
     566             :             case FN_INSERT_FLD_TIME    :
     567           0 :                 nInsertType = TYP_TIMEFLD;
     568           0 :                 bIsText = false;
     569           0 :                 goto FIELD_INSERT;
     570             :             case FN_INSERT_FLD_PGNUMBER:
     571           0 :                 nInsertType = TYP_PAGENUMBERFLD;
     572           0 :                 nInsertFormat = SVX_NUM_PAGEDESC; // Like page template
     573           0 :                 bIsText = false;
     574           0 :                 goto FIELD_INSERT;
     575             :             case FN_INSERT_FLD_PGCOUNT :
     576           0 :                 nInsertType = TYP_DOCSTATFLD;
     577           0 :                 nInsertSubType = 0;
     578           0 :                 bIsText = false;
     579           0 :                 nInsertFormat = SVX_NUM_PAGEDESC;
     580           0 :                 goto FIELD_INSERT;
     581             :             case FN_INSERT_FLD_TOPIC   :
     582           0 :                 nInsertType = TYP_DOCINFOFLD;
     583           0 :                 nInsertSubType = DI_THEMA;
     584           0 :                 goto FIELD_INSERT;
     585             :             case FN_INSERT_FLD_TITLE   :
     586           0 :                 nInsertType = TYP_DOCINFOFLD;
     587           0 :                 nInsertSubType = DI_TITEL;
     588           0 :                 goto FIELD_INSERT;
     589             :             case FN_INSERT_FLD_AUTHOR  :
     590           0 :                 nInsertType = TYP_DOCINFOFLD;
     591           0 :                 nInsertSubType = DI_CREATE|DI_SUB_AUTHOR;
     592             : 
     593             : FIELD_INSERT:
     594             :             {
     595             :                 //format conversion should only be done for number formatter formats
     596           0 :                 if(!nInsertFormat)
     597           0 :                     nInsertFormat = aFldMgr.GetDefaultFormat(nInsertType, bIsText, rSh.GetNumberFormatter());
     598             :                 SwInsertFld_Data aData(nInsertType, nInsertSubType,
     599           0 :                                     OUString(), OUString(), nInsertFormat);
     600           0 :                 aFldMgr.InsertFld(aData);
     601           0 :                 rReq.Done();
     602             :             }
     603           0 :             break;
     604             :             default:
     605             :                 OSL_FAIL("wrong dispatcher");
     606           0 :                 return;
     607           0 :         }
     608             :     }
     609             : }
     610             : 
     611           7 : void SwTextShell::StateField( SfxItemSet &rSet )
     612             : {
     613           7 :     SwWrtShell& rSh = GetShell();
     614           7 :     SfxWhichIter aIter( rSet );
     615           7 :     const SwField* pField = 0;
     616           7 :     int bGetField = sal_False;
     617           7 :     sal_uInt16 nWhich = aIter.FirstWhich();
     618             : 
     619          21 :     while (nWhich)
     620             :     {
     621           7 :         switch (nWhich)
     622             :         {
     623             :         case FN_DELETE_COMMENT:
     624             :         case FN_DELETE_NOTE_AUTHOR:
     625             :         case FN_DELETE_ALL_NOTES:
     626             :         case FN_HIDE_NOTE:
     627             :         case FN_HIDE_NOTE_AUTHOR:
     628             :         case FN_HIDE_ALL_NOTES:
     629             :             {
     630           0 :                 SwPostItMgr* pPostItMgr = GetView().GetPostItMgr();
     631           0 :                 if ( !pPostItMgr )
     632           0 :                     rSet.InvalidateItem( nWhich );
     633           0 :                 else if ( !pPostItMgr->HasActiveSidebarWin() )
     634             :                 {
     635           0 :                     rSet.InvalidateItem( FN_DELETE_COMMENT );
     636           0 :                     rSet.InvalidateItem( FN_HIDE_NOTE );
     637             :                 }
     638             :             }
     639           0 :             break;
     640             : 
     641             :         case FN_EDIT_FIELD:
     642             :             {
     643           7 :                 if( !bGetField )
     644             :                 {
     645           7 :                     pField = rSh.GetCurFld();
     646           7 :                     bGetField = sal_True;
     647             :                 }
     648             : 
     649           7 :                 sal_uInt16 nTempWhich = pField ? pField->GetTyp()->Which() : USHRT_MAX;
     650           7 :                 if( USHRT_MAX == nTempWhich ||
     651           0 :                     RES_POSTITFLD == nTempWhich ||
     652           0 :                     RES_SCRIPTFLD == nTempWhich ||
     653             :                     RES_AUTHORITY == nTempWhich )
     654           7 :                     rSet.DisableItem( nWhich );
     655           0 :                 else if( RES_DDEFLD == nTempWhich &&
     656           0 :                     !((SwDDEFieldType*)pField->GetTyp())->GetBaseLink().IsVisible())
     657             :                 {
     658             :                     // nested links cannot be edited
     659           0 :                     rSet.DisableItem( nWhich );
     660             :                 }
     661             :             }
     662           7 :             break;
     663             : 
     664             :         case FN_EXECUTE_MACROFIELD:
     665             :             {
     666           0 :                 if(!bGetField)
     667             :                 {
     668           0 :                     pField = rSh.GetCurFld();
     669           0 :                     bGetField = sal_True;
     670             :                 }
     671           0 :                 if(!pField || pField->GetTyp()->Which() != RES_MACROFLD)
     672           0 :                     rSet.DisableItem(nWhich);
     673             :             }
     674           0 :             break;
     675             : 
     676             :         case FN_INSERT_FIELD:
     677             :             {
     678           0 :                 if ( rSh.CrsrInsideInputFld() )
     679             :                 {
     680           0 :                     rSet.DisableItem(nWhich);
     681             :                 }
     682             :                 else
     683             :                 {
     684           0 :                     SfxViewFrame* pVFrame = GetView().GetViewFrame();
     685             :                     //#i5788# prevent closing of the field dialog while a modal dialog ( Input field dialog ) is active
     686           0 :                     if(!pVFrame->IsInModalMode() &&
     687           0 :                         pVFrame->KnowsChildWindow(FN_INSERT_FIELD) && !pVFrame->HasChildWindow(FN_INSERT_FIELD_DATA_ONLY) )
     688           0 :                         rSet.Put(SfxBoolItem( FN_INSERT_FIELD, pVFrame->HasChildWindow(nWhich)));
     689             :                     else
     690           0 :                         rSet.DisableItem(FN_INSERT_FIELD);
     691             :                 }
     692             :             }
     693           0 :             break;
     694             : 
     695             :         case FN_INSERT_REF_FIELD:
     696             :             {
     697           0 :                 SfxViewFrame* pVFrame = GetView().GetViewFrame();
     698           0 :                 if ( !pVFrame->KnowsChildWindow(FN_INSERT_FIELD)
     699           0 :                      || rSh.CrsrInsideInputFld() )
     700             :                 {
     701           0 :                     rSet.DisableItem(FN_INSERT_REF_FIELD);
     702             :                 }
     703             :             }
     704           0 :             break;
     705             : 
     706             :         case FN_INSERT_FIELD_CTRL:
     707           0 :                 if ( rSh.CrsrInsideInputFld() )
     708             :                 {
     709           0 :                     rSet.DisableItem(nWhich);
     710             :                 }
     711             :                 else
     712             :                 {
     713           0 :                     rSet.Put(SfxBoolItem( nWhich, GetView().GetViewFrame()->HasChildWindow(FN_INSERT_FIELD)));
     714             :                 }
     715           0 :             break;
     716             : 
     717             :         case FN_REDLINE_COMMENT:
     718           0 :             if (!rSh.GetCurrRedline())
     719           0 :                 rSet.DisableItem(nWhich);
     720           0 :             break;
     721             : 
     722             :         case FN_POSTIT :
     723             :         case FN_JAVAEDIT :
     724             :             {
     725           0 :                 sal_Bool bCurField = sal_False;
     726           0 :                 pField = rSh.GetCurFld();
     727           0 :                 if(nWhich == FN_POSTIT)
     728           0 :                     bCurField = pField && pField->GetTyp()->Which() == RES_POSTITFLD;
     729             :                 else
     730           0 :                     bCurField = pField && pField->GetTyp()->Which() == RES_SCRIPTFLD;
     731             : 
     732           0 :                 if( !bCurField && rSh.IsReadOnlyAvailable() && rSh.HasReadonlySel() )
     733             :                 {
     734           0 :                     rSet.DisableItem(nWhich);
     735             :                 }
     736           0 :                 else if ( rSh.CrsrInsideInputFld() )
     737             :                 {
     738           0 :                     rSet.DisableItem(nWhich);
     739             :                 }
     740             :             }
     741             : 
     742           0 :             break;
     743             : 
     744             :         case FN_INSERT_FLD_AUTHOR:
     745             :         case FN_INSERT_FLD_DATE:
     746             :         case FN_INSERT_FLD_PGCOUNT:
     747             :         case FN_INSERT_FLD_PGNUMBER:
     748             :         case FN_INSERT_FLD_TIME:
     749             :         case FN_INSERT_FLD_TITLE:
     750             :         case FN_INSERT_FLD_TOPIC:
     751             :         case FN_INSERT_DBFIELD:
     752           0 :             if ( rSh.CrsrInsideInputFld() )
     753             :             {
     754           0 :                 rSet.DisableItem(nWhich);
     755             :             }
     756           0 :             break;
     757             : 
     758             :         }
     759           7 :         nWhich = aIter.NextWhich();
     760           7 :     }
     761           7 : }
     762             : 
     763           0 : void SwTextShell::InsertHyperlink(const SvxHyperlinkItem& rHlnkItem)
     764             : {
     765           0 :     const OUString& rName   = rHlnkItem.GetName();
     766           0 :     const OUString& rURL    = rHlnkItem.GetURL();
     767           0 :     const OUString& rTarget = rHlnkItem.GetTargetFrame();
     768           0 :     sal_uInt16 nType =  (sal_uInt16)rHlnkItem.GetInsertMode();
     769           0 :     nType &= ~HLINK_HTMLMODE;
     770           0 :     const SvxMacroTableDtor* pMacroTbl = rHlnkItem.GetMacroTbl();
     771             : 
     772           0 :     SwWrtShell& rSh = GetShell();
     773             : 
     774           0 :     if( rSh.GetSelectionType() & nsSelectionType::SEL_TXT )
     775             :     {
     776           0 :         rSh.StartAction();
     777           0 :         SfxItemSet aSet(GetPool(), RES_TXTATR_INETFMT, RES_TXTATR_INETFMT);
     778           0 :         rSh.GetCurAttr( aSet );
     779             : 
     780             :         const SfxPoolItem* pItem;
     781           0 :         if(SFX_ITEM_SET == aSet.GetItemState(RES_TXTATR_INETFMT, false, &pItem))
     782             :         {
     783             :             // Select links
     784           0 :             rSh.SwCrsrShell::SelectTxtAttr(RES_TXTATR_INETFMT, sal_False);
     785             :         }
     786           0 :         switch (nType)
     787             :         {
     788             :         case HLINK_DEFAULT:
     789             :         case HLINK_FIELD:
     790             :             {
     791           0 :                 SwFmtINetFmt aINetFmt( rURL, rTarget );
     792           0 :                 aINetFmt.SetName(rHlnkItem.GetIntName());
     793           0 :                 if(pMacroTbl)
     794             :                 {
     795           0 :                     const SvxMacro *pMacro = pMacroTbl->Get( SFX_EVENT_MOUSEOVER_OBJECT );
     796           0 :                     if( pMacro )
     797           0 :                         aINetFmt.SetMacro(SFX_EVENT_MOUSEOVER_OBJECT, *pMacro);
     798           0 :                     pMacro = pMacroTbl->Get( SFX_EVENT_MOUSECLICK_OBJECT );
     799           0 :                     if( pMacro )
     800           0 :                         aINetFmt.SetMacro(SFX_EVENT_MOUSECLICK_OBJECT, *pMacro);
     801           0 :                     pMacro = pMacroTbl->Get( SFX_EVENT_MOUSEOUT_OBJECT );
     802           0 :                     if( pMacro )
     803           0 :                         aINetFmt.SetMacro(SFX_EVENT_MOUSEOUT_OBJECT, *pMacro);
     804             :                 }
     805           0 :                 rSh.SttSelect();
     806           0 :                 rSh.InsertURL( aINetFmt, rName, sal_True );
     807           0 :                 rSh.EndSelect();
     808             :             }
     809           0 :             break;
     810             : 
     811             :         case HLINK_BUTTON:
     812           0 :             sal_Bool bSel = rSh.HasSelection();
     813           0 :             if(bSel)
     814           0 :                 rSh.DelRight();
     815           0 :             InsertURLButton( rURL, rTarget, rName );
     816           0 :             rSh.EnterStdMode();
     817           0 :             break;
     818             :         }
     819           0 :         rSh.EndAction();
     820             :     }
     821           0 : }
     822             : 
     823           0 : IMPL_LINK( SwTextShell, RedlineNextHdl, AbstractSvxPostItDialog *, pBtn )
     824             : {
     825           0 :     SwWrtShell* pSh = GetShellPtr();
     826           0 :     AbstractSvxPostItDialog *pDlg = (AbstractSvxPostItDialog*)pBtn;
     827             : 
     828             :     // Insert or change a comment.
     829           0 :     pSh->SetRedlineComment(pDlg->GetNote());
     830             : 
     831           0 :     const SwRangeRedline *pRedline = pSh->GetCurrRedline();
     832             : 
     833           0 :     if (pRedline)
     834             :     {
     835             :         // Traveling only if more than one field.
     836           0 :         if( !pSh->IsCrsrPtAtEnd() )
     837           0 :             pSh->SwapPam(); // Move the cursor behind the Redline.
     838             : 
     839           0 :         pSh->Push();
     840           0 :         const SwRangeRedline *pActRed = pSh->SelNextRedline();
     841           0 :         pSh->Pop(pActRed != 0);
     842             : 
     843           0 :         sal_Bool bEnable = sal_False;
     844             : 
     845           0 :         if (pActRed)
     846             :         {
     847           0 :             pSh->StartAction();
     848           0 :             pSh->Push();
     849           0 :             bEnable = pSh->SelNextRedline() != 0;
     850           0 :             pSh->Pop(sal_False);
     851           0 :             pSh->EndAction();
     852             :         }
     853             : 
     854           0 :         pDlg->EnableTravel(bEnable, true);
     855             : 
     856           0 :         if( pSh->IsCrsrPtAtEnd() )
     857           0 :             pSh->SwapPam();
     858             : 
     859           0 :         pRedline = pSh->GetCurrRedline();
     860           0 :         OUString sComment = convertLineEnd(pRedline->GetComment(), GetSystemLineEnd());
     861             : 
     862           0 :         pDlg->SetNote(sComment);
     863             :         pDlg->ShowLastAuthor( pRedline->GetAuthorString(),
     864             :                     GetAppLangDateTimeString(
     865           0 :                                 pRedline->GetRedlineData().GetTimeStamp() ));
     866             : 
     867           0 :         OUString sTitle(SW_RES(STR_REDLINE_COMMENT));
     868           0 :         ::lcl_AppendRedlineStr( sTitle, pRedline->GetType() );
     869             : 
     870           0 :         pDlg->SetText(sTitle);
     871             :     }
     872             : 
     873           0 :     return 0;
     874             : }
     875             : 
     876           0 : IMPL_LINK( SwTextShell, RedlinePrevHdl, AbstractSvxPostItDialog *, pBtn )
     877             : {
     878           0 :     SwWrtShell* pSh = GetShellPtr();
     879           0 :     AbstractSvxPostItDialog *pDlg = (AbstractSvxPostItDialog*)pBtn;
     880             : 
     881             :     // Insert or change a comment.
     882           0 :     pSh->SetRedlineComment(pDlg->GetNote());
     883             : 
     884           0 :     const SwRangeRedline *pRedline = pSh->GetCurrRedline();
     885             : 
     886           0 :     if (pRedline)
     887             :     {
     888             :         // Traveling only if more than one field.
     889           0 :         pSh->Push();
     890           0 :         const SwRangeRedline *pActRed = pSh->SelPrevRedline();
     891           0 :         pSh->Pop(pActRed != 0);
     892             : 
     893           0 :         sal_Bool bEnable = sal_False;
     894             : 
     895           0 :         if (pActRed)
     896             :         {
     897           0 :             pSh->StartAction();
     898           0 :             pSh->Push();
     899           0 :             bEnable = pSh->SelPrevRedline() != 0;
     900           0 :             pSh->Pop(sal_False);
     901           0 :             pSh->EndAction();
     902             :         }
     903             : 
     904           0 :         pDlg->EnableTravel(true, bEnable);
     905             : 
     906           0 :         pRedline = pSh->GetCurrRedline();
     907           0 :         OUString sComment = convertLineEnd(pRedline->GetComment(), GetSystemLineEnd());
     908             : 
     909           0 :         pDlg->SetNote(sComment);
     910             :         pDlg->ShowLastAuthor(pRedline->GetAuthorString(),
     911             :                 GetAppLangDateTimeString(
     912           0 :                                 pRedline->GetRedlineData().GetTimeStamp() ));
     913             : 
     914           0 :         OUString sTitle(SW_RES(STR_REDLINE_COMMENT));
     915           0 :         ::lcl_AppendRedlineStr( sTitle, pRedline->GetType() );
     916             : 
     917           0 :         pDlg->SetText(sTitle);
     918             :     }
     919             : 
     920           0 :     return 0;
     921         111 : }
     922             : 
     923             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10