xref: /aoo41x/main/sw/source/ui/shells/textfld.cxx (revision dec99bbd)
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 
358             case FN_POSTIT:
359                 {
360                     SwPostItField* pPostIt = dynamic_cast<SwPostItField*>(aFldMgr.GetCurFld());
361                     sal_Bool bNew = !(pPostIt && pPostIt->GetTyp()->Which() == RES_POSTITFLD);
362                     if (bNew || GetView().GetPostItMgr()->IsAnswer())
363                     {
364                         SvtUserOptions aUserOpt;
365                         String sAuthor;
366                         if( !(sAuthor = aUserOpt.GetFullName()).Len())
367                             if( !(sAuthor = aUserOpt.GetID()).Len() )
368                                 sAuthor = String( SW_RES( STR_REDLINE_UNKNOWN_AUTHOR ));
369 
370                         if( rSh.HasSelection() )
371                         {
372                             rSh.NormalizePam( sal_False );
373                             rSh.KillPams();
374                         }
375 
376                         // #120513# Inserting a comment into an autocompletion crashes
377                         // --> suggestion has to be removed before
378                         GetView().GetEditWin().StopQuickHelp();
379 
380                         SwInsertFld_Data aData(TYP_POSTITFLD, 0, sAuthor, aEmptyStr, 0);
381                         aFldMgr.InsertFld( aData );
382 
383                         rSh.Push();
384                         rSh.SwCrsrShell::Left(1, CRSR_SKIP_CHARS, sal_False);
385                         pPostIt = (SwPostItField*)aFldMgr.GetCurFld();
386                         rSh.Pop(sal_False);	// Cursorpos restaurieren
387                     }
388 
389                     if (pPostIt)
390                     {
391                         SwFieldType* pType = rSh.GetDoc()->GetFldType(RES_POSTITFLD, aEmptyStr,false);
392                         SwIterator<SwFmtFld,SwFieldType> aIter( *pType );
393                         SwFmtFld* pSwFmtFld = aIter.First();
394                         while( pSwFmtFld )
395                         {
396                             if ( pSwFmtFld->GetField() == pPostIt )
397                             {
398                                 pSwFmtFld->Broadcast( SwFmtFldHint( 0, SWFMTFLD_FOCUS, &GetView() ) );
399                                 break;
400                             }
401                             pSwFmtFld = aIter.Next();
402                         }
403                     }
404                 }
405                 break;
406 
407 			case FN_REDLINE_COMMENT:
408 			{
409 				/*	this code can be used once we want redline comments in the margin, all other stuff can
410 					then be deleted
411 				String sComment;
412 				const SwRedline *pRedline = rSh.GetCurrRedline();
413 
414 				if (pRedline)
415 				{
416 					sComment = pRedline->GetComment();
417 					if ( sComment == String(rtl::OUString::createFromAscii("")) )
418 						GetView().GetDocShell()->Broadcast(SwRedlineHint(pRedline,SWREDLINE_INSERTED));
419 					const_cast<SwRedline*>(pRedline)->Broadcast(SwRedlineHint(pRedline,SWREDLINE_FOCUS,&GetView()));
420 				}
421 				*/
422 
423 				String sComment;
424 				const SwRedline *pRedline = rSh.GetCurrRedline();
425 
426 				if (pRedline)
427 				{
428 					sComment = pRedline->GetComment();
429 
430 
431 					sal_Bool bTravel = sal_False;
432 
433 					SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
434                     DBG_ASSERT(pFact, "Dialogdiet fail!");
435 					::DialogGetRanges fnGetRange = pFact->GetDialogGetRangesFunc( RID_SVXDLG_POSTIT );
436                     DBG_ASSERT(fnGetRange, "Dialogdiet fail! GetRanges()");
437 					SfxItemSet aSet(GetPool(), fnGetRange());
438 					aSet.Put(SvxPostItTextItem(sComment.ConvertLineEnd(), SID_ATTR_POSTIT_TEXT));
439 					aSet.Put(SvxPostItAuthorItem(pRedline->GetAuthorString(), SID_ATTR_POSTIT_AUTHOR));
440 
441 					aSet.Put( SvxPostItDateItem( GetAppLangDateTimeString(
442 								pRedline->GetRedlineData().GetTimeStamp() ),
443 								SID_ATTR_POSTIT_DATE ));
444 
445 					// Traveling nur bei mehr als einem Feld
446 					rSh.StartAction();
447 
448 					rSh.Push();
449 					const SwRedline *pActRed = rSh.SelPrevRedline();
450 
451 					if (pActRed == pRedline)
452 					{	// Neuer Cursor steht am Anfang des Current Redlines
453 						rSh.Pop();	// Alten Cursor wegwerfen
454 						rSh.Push();
455 						pActRed = rSh.SelPrevRedline();
456 					}
457 
458 					sal_Bool bPrev = pActRed != 0;
459 					rSh.Pop(sal_False);
460 					rSh.EndAction();
461 
462 					rSh.ClearMark();
463 					rSh.SelNextRedline();	// Aktueller Redline wird selektiert
464 
465 					rSh.StartAction();
466 					rSh.Push();
467 					pActRed = rSh.SelNextRedline();
468 					sal_Bool bNext = pActRed != 0;
469 					rSh.Pop(sal_False);	// Cursorpos restaurieren
470 
471 					if( rSh.IsCrsrPtAtEnd() )
472 						rSh.SwapPam();
473 
474 					rSh.EndAction();
475 
476 					bTravel |= bNext|bPrev;
477 
478 					SvxAbstractDialogFactory* pFact2 = SvxAbstractDialogFactory::Create();
479                     DBG_ASSERT(pFact2, "Dialogdiet fail!");
480                     AbstractSvxPostItDialog* pDlg = pFact2->CreateSvxPostItDialog( pMDI, aSet, bTravel, sal_True );
481                     DBG_ASSERT(pDlg, "Dialogdiet fail!");
482 					pDlg->HideAuthor();
483 
484 					String sTitle(SW_RES(STR_REDLINE_COMMENT));
485 					::lcl_AppendRedlineStr( sTitle, pRedline->GetType() );
486 
487 					pDlg->SetText(sTitle);
488 
489 					if (bTravel)
490 					{
491 						pDlg->EnableTravel(bNext, bPrev);
492 						pDlg->SetPrevHdl(LINK(this, SwTextShell, RedlinePrevHdl));
493 						pDlg->SetNextHdl(LINK(this, SwTextShell, RedlineNextHdl));
494 					}
495 
496 					rSh.SetCareWin(pDlg->GetWindow());
497 					bNoInterrupt = sal_True;
498 
499 					if ( pDlg->Execute() == RET_OK )
500 					{
501 						const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
502 						String sMsg(((const SvxPostItTextItem&)pOutSet->Get(SID_ATTR_POSTIT_TEXT)).GetValue());
503 
504 						// Kommentar einfuegen bzw aendern
505 						rSh.SetRedlineComment(sMsg);
506 					}
507 
508 					delete pDlg;
509 					rSh.SetCareWin(NULL);
510 					bNoInterrupt = sal_False;
511 					rSh.ClearMark();
512 					GetView().AttrChangedNotify(GetShellPtr());
513 				}
514 			}
515 			break;
516 
517 			case FN_JAVAEDIT:
518 			{
519                 String aType, aText;
520                 sal_Bool bIsUrl=sal_False;
521                 sal_Bool bNew=sal_False, bUpdate=sal_False;
522                 SwFldMgr* pMgr = new SwFldMgr;
523                 if ( pItem )
524                 {
525                     aText = ((SfxStringItem*)pItem)->GetValue();
526                     SFX_REQUEST_ARG( rReq, pType, SfxStringItem, FN_PARAM_2 , sal_False );
527                     SFX_REQUEST_ARG( rReq, pIsUrl, SfxBoolItem, FN_PARAM_1 , sal_False );
528                     if ( pType )
529                         aType = pType->GetValue();
530                     if ( pIsUrl )
531                         bIsUrl = pIsUrl->GetValue();
532 
533                     SwScriptField* pFld = (SwScriptField*)pMgr->GetCurFld();
534                     bNew = !pFld || !(pFld->GetTyp()->Which() == RES_SCRIPTFLD);
535                     bUpdate = pFld && ( bIsUrl != pFld->GetFormat() || pFld->GetPar2() != aType || pFld->GetPar1() != aText );
536                 }
537                 else
538                 {
539                     SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
540                     DBG_ASSERT(pFact, "Dialogdiet fail!");
541                     AbstractJavaEditDialog* pDlg = pFact->CreateJavaEditDialog( DLG_JAVAEDIT,
542 															pMDI, &rSh);
543                     DBG_ASSERT(pDlg, "Dialogdiet fail!");
544 					if ( pDlg->Execute() )
545                     {
546                         aType = pDlg->GetType();
547                         aText = pDlg->GetText();
548                         bIsUrl = pDlg->IsUrl();
549                         bNew = pDlg->IsNew();
550                         bUpdate = pDlg->IsUpdate();
551                         rReq.AppendItem( SfxStringItem( FN_JAVAEDIT, aText ) );
552                         rReq.AppendItem( SfxStringItem( FN_PARAM_2, aType ) );
553                         rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bIsUrl ) );
554                     }
555 
556                     delete pDlg;
557                 }
558 
559                 if( bNew )
560                 {
561                     SwInsertFld_Data aData(TYP_SCRIPTFLD, 0, aType, aText, bIsUrl);
562                     pMgr->InsertFld(aData);
563                     rReq.Done();
564                 }
565                 else if( bUpdate )
566                 {
567                     pMgr->UpdateCurFld( bIsUrl, aType, aText );
568                     rSh.SetUndoNoResetModified();
569                     rReq.Done();
570                 }
571                 else
572                     rReq.Ignore();
573 			}
574 			break;
575 
576 			case FN_INSERT_FLD_DATE    :
577 				nInsertType = TYP_DATEFLD;
578                 bIsText = sal_False;
579                 goto FIELD_INSERT;
580 			case FN_INSERT_FLD_TIME    :
581 				nInsertType = TYP_TIMEFLD;
582                 bIsText = sal_False;
583                 goto FIELD_INSERT;
584 			case FN_INSERT_FLD_PGNUMBER:
585 				nInsertType = TYP_PAGENUMBERFLD;
586 				nInsertFormat = SVX_NUM_PAGEDESC; // wie Seitenvorlage
587                 bIsText = sal_False;
588                 goto FIELD_INSERT;
589 			case FN_INSERT_FLD_PGCOUNT :
590 				nInsertType = TYP_DOCSTATFLD;
591 				nInsertSubType = 0;
592                 bIsText = sal_False;
593                 nInsertFormat = SVX_NUM_PAGEDESC;
594 				goto FIELD_INSERT;
595 			case FN_INSERT_FLD_TOPIC   :
596 				nInsertType = TYP_DOCINFOFLD;
597 				nInsertSubType = DI_THEMA;
598 				goto FIELD_INSERT;
599 			case FN_INSERT_FLD_TITLE   :
600 				nInsertType = TYP_DOCINFOFLD;
601 				nInsertSubType = DI_TITEL;
602 				goto FIELD_INSERT;
603 			case FN_INSERT_FLD_AUTHOR  :
604                 nInsertType = TYP_DOCINFOFLD;
605                 nInsertSubType = DI_CREATE|DI_SUB_AUTHOR;
606 
607 FIELD_INSERT:
608             {
609                 //format conversion should only be done for number formatter formats
610                 if(!nInsertFormat)
611                     nInsertFormat = aFldMgr.GetDefaultFormat(nInsertType, bIsText, rSh.GetNumberFormatter());
612                 SwInsertFld_Data aData(nInsertType, nInsertSubType,
613                                     aEmptyStr, aEmptyStr, nInsertFormat);
614                 aFldMgr.InsertFld(aData);
615 				rReq.Done();
616             }
617 			break;
618 			default:
619 				ASSERT(sal_False, falscher Dispatcher);
620 				return;
621 		}
622 	}
623 }
624 
625 void SwTextShell::StateField( SfxItemSet &rSet )
626 {
627     SwWrtShell& rSh = GetShell();
628     SfxWhichIter aIter( rSet );
629     const SwField* pField = 0;
630     int bGetField = sal_False;
631     sal_uInt16 nWhich = aIter.FirstWhich();
632 
633     while (nWhich)
634     {
635         switch (nWhich)
636         {
637         case FN_DELETE_COMMENT:
638         case FN_DELETE_NOTE_AUTHOR:
639         case FN_DELETE_ALL_NOTES:
640         case FN_HIDE_NOTE:
641         case FN_HIDE_NOTE_AUTHOR:
642         case FN_HIDE_ALL_NOTES:
643             {
644                 SwPostItMgr* pPostItMgr = GetView().GetPostItMgr();
645                 if ( !pPostItMgr )
646                     rSet.InvalidateItem( nWhich );
647                 else if ( !pPostItMgr->HasActiveSidebarWin() )
648                 {
649                     rSet.InvalidateItem( FN_DELETE_COMMENT );
650                     rSet.InvalidateItem( FN_HIDE_NOTE );
651                 }
652             }
653             break;
654 
655         case FN_EDIT_FIELD:
656             {
657                 if( !bGetField )
658                 {
659                     pField = rSh.GetCurFld();
660                     bGetField = sal_True;
661                 }
662 
663                 sal_uInt16 nTempWhich = pField ? pField->GetTyp()->Which() : USHRT_MAX;
664                 if(	USHRT_MAX == nTempWhich ||
665                     RES_POSTITFLD == nTempWhich ||
666                     RES_SCRIPTFLD == nTempWhich ||
667                     RES_AUTHORITY == nTempWhich )
668                     rSet.DisableItem( nWhich );
669                 else if( RES_DDEFLD == nTempWhich &&
670                     !((SwDDEFieldType*)pField->GetTyp())->GetBaseLink().IsVisible())
671                 {
672                     // nested links cannot be edited
673                     rSet.DisableItem( nWhich );
674                 }
675             }
676             break;
677 
678         case FN_EXECUTE_MACROFIELD:
679             {
680                 if(!bGetField)
681                 {
682                     pField = rSh.GetCurFld();
683                     bGetField = sal_True;
684                 }
685                 if(!pField || pField->GetTyp()->Which() != RES_MACROFLD)
686                     rSet.DisableItem(nWhich);
687             }
688             break;
689 
690         case FN_INSERT_FIELD:
691             {
692                 if ( rSh.CrsrInsideInputFld() )
693                 {
694                     rSet.DisableItem(nWhich);
695                 }
696                 else
697                 {
698                     SfxViewFrame* pVFrame = GetView().GetViewFrame();
699                     //#i5788# prevent closing of the field dialog while a modal dialog ( Input field dialog ) is active
700                     if(!pVFrame->IsInModalMode() &&
701                         pVFrame->KnowsChildWindow(FN_INSERT_FIELD) && !pVFrame->HasChildWindow(FN_INSERT_FIELD_DATA_ONLY) )
702                         rSet.Put(SfxBoolItem( FN_INSERT_FIELD, pVFrame->HasChildWindow(nWhich)));
703                     else
704                         rSet.DisableItem(FN_INSERT_FIELD);
705                 }
706             }
707             break;
708 
709         case FN_INSERT_REF_FIELD:
710             {
711                 SfxViewFrame* pVFrame = GetView().GetViewFrame();
712                 if ( !pVFrame->KnowsChildWindow(FN_INSERT_FIELD)
713                      || rSh.CrsrInsideInputFld() )
714                 {
715                     rSet.DisableItem(FN_INSERT_REF_FIELD);
716                 }
717             }
718             break;
719 
720         case FN_INSERT_FIELD_CTRL:
721                 if ( rSh.CrsrInsideInputFld() )
722                 {
723                     rSet.DisableItem(nWhich);
724                 }
725                 else
726                 {
727                     rSet.Put(SfxBoolItem( nWhich, GetView().GetViewFrame()->HasChildWindow(FN_INSERT_FIELD)));
728                 }
729             break;
730 
731         case FN_REDLINE_COMMENT:
732             if (!rSh.GetCurrRedline())
733                 rSet.DisableItem(nWhich);
734             break;
735 
736         case FN_POSTIT :
737         case FN_JAVAEDIT :
738             {
739                 sal_Bool bCurField = sal_False;
740                 pField = rSh.GetCurFld();
741                 if(nWhich == FN_POSTIT)
742                     bCurField = pField && pField->GetTyp()->Which() == RES_POSTITFLD;
743                 else
744                     bCurField = pField && pField->GetTyp()->Which() == RES_SCRIPTFLD;
745 
746                 if( !bCurField && rSh.IsReadOnlyAvailable() && rSh.HasReadonlySel() )
747                 {
748                     rSet.DisableItem(nWhich);
749                 }
750                 else if ( rSh.CrsrInsideInputFld() )
751                 {
752                     rSet.DisableItem(nWhich);
753                 }
754             }
755 
756             break;
757 
758         case FN_INSERT_FLD_AUTHOR:
759         case FN_INSERT_FLD_DATE:
760         case FN_INSERT_FLD_PGCOUNT:
761         case FN_INSERT_FLD_PGNUMBER:
762         case FN_INSERT_FLD_TIME:
763         case FN_INSERT_FLD_TITLE:
764         case FN_INSERT_FLD_TOPIC:
765         case FN_INSERT_DBFIELD:
766             if ( rSh.CrsrInsideInputFld() )
767             {
768                 rSet.DisableItem(nWhich);
769             }
770             break;
771 
772         }
773         nWhich = aIter.NextWhich();
774     }
775 }
776 
777 /*---------------------------------------------------------------------------
778 	Beschreibung:
779  ----------------------------------------------------------------------------*/
780 
781 
782 void SwTextShell::InsertHyperlink(const SvxHyperlinkItem& rHlnkItem)
783 {
784 	const String& rName   = rHlnkItem.GetName();
785 	const String& rURL    = rHlnkItem.GetURL();
786 	const String& rTarget = rHlnkItem.GetTargetFrame();
787 	sal_uInt16 nType =  (sal_uInt16)rHlnkItem.GetInsertMode();
788 	nType &= ~HLINK_HTMLMODE;
789 	const SvxMacroTableDtor* pMacroTbl = rHlnkItem.GetMacroTbl();
790 
791 	SwWrtShell& rSh = GetShell();
792 
793 	if( rSh.GetSelectionType() & nsSelectionType::SEL_TXT )
794 	{
795         rSh.StartAction();
796         SfxItemSet aSet(GetPool(), RES_TXTATR_INETFMT, RES_TXTATR_INETFMT);
797         rSh.GetCurAttr( aSet );
798 
799         const SfxPoolItem* pItem;
800         if(SFX_ITEM_SET == aSet.GetItemState(RES_TXTATR_INETFMT, sal_False, &pItem))
801         {
802             // Links selektieren
803             rSh.SwCrsrShell::SelectTxtAttr(RES_TXTATR_INETFMT, sal_False);
804         }
805         switch (nType)
806 		{
807 		case HLINK_DEFAULT:
808 		case HLINK_FIELD:
809 			{
810                 SwFmtINetFmt aINetFmt( rURL, rTarget );
811 				aINetFmt.SetName(rHlnkItem.GetIntName());
812 				if(pMacroTbl)
813 				{
814 					SvxMacro *pMacro = pMacroTbl->Get( SFX_EVENT_MOUSEOVER_OBJECT );
815 					if( pMacro )
816 						aINetFmt.SetMacro(SFX_EVENT_MOUSEOVER_OBJECT, *pMacro);
817 					pMacro = pMacroTbl->Get( SFX_EVENT_MOUSECLICK_OBJECT );
818 					if( pMacro )
819 						aINetFmt.SetMacro(SFX_EVENT_MOUSECLICK_OBJECT, *pMacro);
820 					pMacro = pMacroTbl->Get( SFX_EVENT_MOUSEOUT_OBJECT );
821 					if( pMacro )
822 						aINetFmt.SetMacro(SFX_EVENT_MOUSEOUT_OBJECT, *pMacro);
823 				}
824 				rSh.SttSelect();
825 				rSh.InsertURL( aINetFmt, rName, sal_True );
826 				rSh.EndSelect();
827             }
828 			break;
829 
830 		case HLINK_BUTTON:
831             sal_Bool bSel = rSh.HasSelection();
832             if(bSel)
833                 rSh.DelRight();
834             InsertURLButton( rURL, rTarget, rName );
835 			rSh.EnterStdMode();
836 			break;
837 		}
838         rSh.EndAction();
839     }
840 }
841 
842 IMPL_LINK( SwTextShell, RedlineNextHdl, AbstractSvxPostItDialog *, pBtn )
843 {
844 	SwWrtShell* pSh = GetShellPtr();
845 	AbstractSvxPostItDialog *pDlg = (AbstractSvxPostItDialog*)pBtn;
846 
847 	// Kommentar einfuegen bzw aendern
848 	pSh->SetRedlineComment(pDlg->GetNote());
849 
850 	const SwRedline *pRedline = pSh->GetCurrRedline();
851 
852 	String sComment;
853 
854 	if (pRedline)
855 	{
856 		// Traveling nur bei mehr als einem Feld
857 		if( !pSh->IsCrsrPtAtEnd() )
858 			pSh->SwapPam();	// Cursor hinter den Redline stellen
859 
860 		pSh->Push();
861 		const SwRedline *pActRed = pSh->SelNextRedline();
862 		pSh->Pop(pActRed != 0);
863 
864 		sal_Bool bEnable = sal_False;
865 
866 		if (pActRed)
867 		{
868 			pSh->StartAction();
869 			pSh->Push();
870 			bEnable = pSh->SelNextRedline() != 0;
871 			pSh->Pop(sal_False);
872 			pSh->EndAction();
873 		}
874 
875 		pDlg->EnableTravel(bEnable, sal_True);
876 
877 		if( pSh->IsCrsrPtAtEnd() )
878 			pSh->SwapPam();
879 
880 		pRedline = pSh->GetCurrRedline();
881 		sComment = pRedline->GetComment();
882 
883 		pDlg->SetNote( sComment.ConvertLineEnd() );
884 		pDlg->ShowLastAuthor( pRedline->GetAuthorString(),
885 					GetAppLangDateTimeString(
886 								pRedline->GetRedlineData().GetTimeStamp() ));
887 
888 		String sTitle(SW_RES(STR_REDLINE_COMMENT));
889 		::lcl_AppendRedlineStr( sTitle, pRedline->GetType() );
890 
891 		pDlg->SetText(sTitle);
892 	}
893 
894 	return 0;
895 }
896 
897 IMPL_LINK( SwTextShell, RedlinePrevHdl, AbstractSvxPostItDialog *, pBtn )
898 {
899 	SwWrtShell* pSh = GetShellPtr();
900 	AbstractSvxPostItDialog *pDlg = (AbstractSvxPostItDialog*)pBtn;
901 
902 	// Kommentar einfuegen bzw aendern
903 	pSh->SetRedlineComment(pDlg->GetNote());
904 
905 	const SwRedline *pRedline = pSh->GetCurrRedline();
906 
907 	String sComment;
908 
909 	if (pRedline)
910 	{
911 		// Traveling nur bei mehr als einem Feld
912 		pSh->Push();
913 		const SwRedline *pActRed = pSh->SelPrevRedline();
914 		pSh->Pop(pActRed != 0);
915 
916 		sal_Bool bEnable = sal_False;
917 
918 		if (pActRed)
919 		{
920 			pSh->StartAction();
921 			pSh->Push();
922 			bEnable = pSh->SelPrevRedline() != 0;
923 			pSh->Pop(sal_False);
924 			pSh->EndAction();
925 		}
926 
927 		pDlg->EnableTravel(sal_True, bEnable);
928 
929 		pRedline = pSh->GetCurrRedline();
930 		sComment = pRedline->GetComment();
931 
932 		pDlg->SetNote(sComment.ConvertLineEnd());
933 		pDlg->ShowLastAuthor(pRedline->GetAuthorString(),
934 				GetAppLangDateTimeString(
935 								pRedline->GetRedlineData().GetTimeStamp() ));
936 
937 		String sTitle(SW_RES(STR_REDLINE_COMMENT));
938 		::lcl_AppendRedlineStr( sTitle, pRedline->GetType() );
939 
940 		pDlg->SetText(sTitle);
941 	}
942 
943 	return 0;
944 }
945 
946 
947