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