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