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