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