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