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