Update ooo320-m1
[ooovba.git] / sw / source / ui / shells / textfld.cxx
blob529ac59604f9b39706e36012865ae17f1a66c87b
1 /************ *************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: textfld.cxx,v $
10 * $Revision: 1.38.190.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #include <crsskip.hxx>
35 #include <hintids.hxx> //_immer_ vor den solar-Items
37 #include <sfx2/lnkbase.hxx>
38 #include <fmtfld.hxx>
39 #include <tools/urlobj.hxx>
40 #include <vcl/msgbox.hxx>
41 #include <svtools/itempool.hxx>
42 #include <svtools/useroptions.hxx>
43 #include <svtools/whiter.hxx>
44 #include <svtools/eitem.hxx>
45 #include <svtools/macitem.hxx>
46 #include <sfx2/viewfrm.hxx>
47 #include <sfx2/request.hxx>
48 #include <svx/postattr.hxx>
49 #include <svx/hlnkitem.hxx>
51 #include <svx/svxdlg.hxx>
52 #include <svx/linkmgr.hxx>
53 #include <unotools/localedatawrapper.hxx>
54 #include <sfx2/dispatch.hxx>
55 #include <fmtinfmt.hxx>
56 #include <fldwrap.hxx>
57 #include <redline.hxx>
58 #include <view.hxx>
59 #include <wrtsh.hxx>
60 #include <basesh.hxx>
61 #include <wrtsh.hxx>
62 #include <flddat.hxx>
63 #include <numrule.hxx>
64 #include <textsh.hxx>
65 #include <docsh.hxx>
66 #include <docufld.hxx>
67 #include <usrfld.hxx>
68 #include <ddefld.hxx>
69 #include <expfld.hxx>
70 #include <fldmgr.hxx>
71 #include <uitool.hxx>
73 #include <cmdid.h>
74 #include <shells.hrc>
76 #include <sfx2/app.hxx>
77 #include <svx/svxdlg.hxx>
78 #include <svx/dialogs.hrc>
79 #include "swabstdlg.hxx"
80 #include "dialog.hrc"
81 #include <fldui.hrc>
82 #include <doc.hxx>
84 #include <app.hrc>
86 #include "PostItMgr.hxx"
87 #include "postit.hxx"
89 using namespace nsSwDocInfoSubType;
92 extern BOOL bNoInterrupt; // in mainwn.cxx
94 String& lcl_AppendRedlineStr( String& rStr, USHORT nRedlId )
96 USHORT nResId = 0;
97 switch( nRedlId )
99 case nsRedlineType_t::REDLINE_INSERT: nResId = STR_REDLINE_INSERTED; break;
100 case nsRedlineType_t::REDLINE_DELETE: nResId = STR_REDLINE_DELETED; break;
101 case nsRedlineType_t::REDLINE_FORMAT: nResId = STR_REDLINE_FORMATED; break;
102 case nsRedlineType_t::REDLINE_TABLE: nResId = STR_REDLINE_TABLECHG; break;
103 case nsRedlineType_t::REDLINE_FMTCOLL: nResId = STR_REDLINE_FMTCOLLSET; break;
105 if( nResId )
106 rStr += SW_RESSTR( nResId );
107 return rStr;
110 // STATIC DATA -----------------------------------------------------------
112 void SwTextShell::ExecField(SfxRequest &rReq)
114 SwWrtShell& rSh = GetShell();
115 const SfxPoolItem* pItem = 0;
117 USHORT nSlot = rReq.GetSlot();
118 const SfxItemSet* pArgs = rReq.GetArgs();
119 if(pArgs)
120 pArgs->GetItemState(GetPool().GetWhich(nSlot), FALSE, &pItem);
122 Window *pMDI = &GetView().GetViewFrame()->GetWindow();
123 BOOL bMore = FALSE;
124 BOOL bIsText = TRUE;
125 USHORT nInsertType = 0;
126 USHORT nInsertSubType = 0;
127 ULONG nInsertFormat = 0;
129 switch(nSlot)
131 case FN_EDIT_FIELD:
133 SwField* pFld = rSh.GetCurFld();
134 if( pFld )
136 switch ( pFld->GetTypeId() )
138 case TYP_DDEFLD:
140 ::sfx2::SvBaseLink& rLink = ((SwDDEFieldType*)pFld->GetTyp())->
141 GetBaseLink();
142 if(rLink.IsVisible())
144 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
145 SfxAbstractLinksDialog* pDlg = pFact->CreateLinksDialog( pMDI, &rSh.GetLinkManager(), FALSE, &rLink );
146 if ( pDlg )
148 pDlg->Execute();
149 delete pDlg;
152 break;
154 default:
156 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
157 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
159 SfxAbstractDialog* pDlg = pFact->CreateSwFldEditDlg( GetView(),RC_DLG_SWFLDEDITDLG );
160 DBG_ASSERT(pDlg, "Dialogdiet fail!");
161 pDlg->Execute();
162 delete pDlg;
166 break;
168 case FN_EXECUTE_MACROFIELD:
170 SwField* pFld = rSh.GetCurFld();
171 if(pFld && pFld->GetTyp()->Which() == RES_MACROFLD)
174 const String& rMacro = ((SwMacroField*)pFld)->GetMacro();
175 USHORT nPos = rMacro.Search('.', 0);
176 if(nPos != STRING_NOTFOUND)
178 SvxMacro aMacro( rMacro.Copy(nPos + 1), rMacro.Copy(0,nPos), STARBASIC );
179 rSh.ExecMacro(aMacro);
183 break;
185 case FN_GOTO_NEXT_INPUTFLD:
186 case FN_GOTO_PREV_INPUTFLD:
188 BOOL bRet = FALSE;
189 SwFieldType* pFld = rSh.GetFldType( 0, RES_INPUTFLD );
190 if( pFld && rSh.MoveFldType( pFld,
191 FN_GOTO_NEXT_INPUTFLD == nSlot ))
193 rSh.ClearMark();
194 rSh.StartInputFldDlg( rSh.GetCurFld(), FALSE );
195 bRet = TRUE;
198 rReq.SetReturnValue( SfxBoolItem( nSlot, bRet ));
200 break;
202 default:
203 bMore = TRUE;
205 if(bMore)
207 // hier kommen die Slots mit FldMgr
208 SwFldMgr aFldMgr(GetShellPtr());
209 switch(nSlot)
211 case FN_INSERT_DBFIELD:
213 BOOL bRes = FALSE;
214 if( pItem )
216 ULONG nFormat = 0;
217 USHORT nType = 0;
218 String aPar1 = ((SfxStringItem *)pItem)->GetValue();
219 String aPar2;
220 sal_Int32 nCommand = 0;
222 if( SFX_ITEM_SET == pArgs->GetItemState( FN_PARAM_FIELD_TYPE,
223 FALSE, &pItem ))
224 nType = ((SfxUInt16Item *)pItem)->GetValue();
225 aPar1 += DB_DELIM;
226 if( SFX_ITEM_SET == pArgs->GetItemState(
227 FN_PARAM_1, FALSE, &pItem ))
229 aPar1 += ((SfxStringItem *)pItem)->GetValue();
231 if( SFX_ITEM_SET == pArgs->GetItemState(
232 FN_PARAM_3, FALSE, &pItem ))
233 nCommand = ((SfxInt32Item*)pItem)->GetValue();
234 aPar1 += DB_DELIM;
235 aPar1 += String::CreateFromInt32(nCommand);
236 aPar1 += DB_DELIM;
237 if( SFX_ITEM_SET == pArgs->GetItemState(
238 FN_PARAM_2, FALSE, &pItem ))
240 aPar1 += ((SfxStringItem *)pItem)->GetValue();
242 if( SFX_ITEM_SET == pArgs->GetItemState(
243 FN_PARAM_FIELD_CONTENT, FALSE, &pItem ))
244 aPar2 = ((SfxStringItem *)pItem)->GetValue();
245 if( SFX_ITEM_SET == pArgs->GetItemState(
246 FN_PARAM_FIELD_FORMAT, FALSE, &pItem ))
247 nFormat = ((SfxUInt32Item *)pItem)->GetValue();
248 DBG_WARNING("Command is not yet used");
249 sal_Unicode cSeparator = ' ';
250 SwInsertFld_Data aData(nType, 0, aPar1, aPar2, nFormat, GetShellPtr(), cSeparator );
251 bRes = aFldMgr.InsertFld(aData);
253 rReq.SetReturnValue(SfxBoolItem( nSlot, bRes ));
255 break;
256 case FN_INSERT_FIELD_CTRL:
257 case FN_INSERT_FIELD:
259 BOOL bRes = FALSE;
260 if( pItem && nSlot != FN_INSERT_FIELD_CTRL)
262 ULONG nFormat = 0;
263 USHORT nType = 0;
264 USHORT nSubType = 0;
265 String aPar1 = ((SfxStringItem *)pItem)->GetValue();
266 String aPar2;
267 sal_Unicode cSeparator = ' ';
269 if( SFX_ITEM_SET == pArgs->GetItemState( FN_PARAM_FIELD_TYPE,
270 FALSE, &pItem ))
271 nType = ((SfxUInt16Item *)pItem)->GetValue();
272 if( SFX_ITEM_SET == pArgs->GetItemState( FN_PARAM_FIELD_SUBTYPE,
273 FALSE, &pItem ))
274 nSubType = ((SfxUInt16Item *)pItem)->GetValue();
275 if( SFX_ITEM_SET == pArgs->GetItemState(
276 FN_PARAM_FIELD_CONTENT, FALSE, &pItem ))
277 aPar2 = ((SfxStringItem *)pItem)->GetValue();
278 if( SFX_ITEM_SET == pArgs->GetItemState(
279 FN_PARAM_FIELD_FORMAT, FALSE, &pItem ))
280 nFormat = ((SfxUInt32Item *)pItem)->GetValue();
281 if( SFX_ITEM_SET == pArgs->GetItemState(
282 FN_PARAM_3, FALSE, &pItem ))
284 String sTmp = ((SfxStringItem *)pItem)->GetValue();
285 if(sTmp.Len())
286 cSeparator = sTmp.GetChar(0);
288 SwInsertFld_Data aData(nType, nSubType, aPar1, aPar2, nFormat, GetShellPtr(), cSeparator );
289 bRes = aFldMgr.InsertFld( aData );
291 else
292 //#i5788# prevent closing of the field dialog while a modal dialog ( Input field dialog ) is active
293 if(!GetView().GetViewFrame()->IsInModalMode())
295 SfxViewFrame* pVFrame = GetView().GetViewFrame();
296 pVFrame->ToggleChildWindow(FN_INSERT_FIELD);
297 bRes = pVFrame->GetChildWindow( nSlot ) != 0;
298 Invalidate(rReq.GetSlot());
299 Invalidate(FN_INSERT_FIELD_CTRL);
300 rReq.Ignore();
302 rReq.SetReturnValue(SfxBoolItem( nSlot, bRes ));
304 break;
306 case FN_INSERT_REF_FIELD:
308 SfxViewFrame* pVFrame = GetView().GetViewFrame();
309 if (!pVFrame->HasChildWindow(FN_INSERT_FIELD))
310 pVFrame->ToggleChildWindow(FN_INSERT_FIELD); // Dialog anzeigen
312 // Flddlg auf neue TabPage umschalten
313 USHORT nId = SwFldDlgWrapper::GetChildWindowId();
314 SwFldDlgWrapper *pWrp = (SwFldDlgWrapper*)pVFrame->GetChildWindow(nId);
315 if (pWrp)
316 pWrp->ShowPage();
317 rReq.Ignore();
319 break;
320 case FN_DELETE_NOTE:
321 if ( GetView().GetPostItMgr() && GetView().GetPostItMgr()->GetActivePostIt() )
322 GetView().GetPostItMgr()->GetActivePostIt()->Delete();
323 break;
324 case FN_DELETE_ALL_NOTES:
325 if ( GetView().GetPostItMgr() )
326 GetView().GetPostItMgr()->Delete();
327 break;
328 case FN_DELETE_NOTE_AUTHOR:
330 SFX_REQUEST_ARG( rReq, pNoteItem, SfxStringItem, nSlot, FALSE);
331 if ( pNoteItem && GetView().GetPostItMgr() )
332 GetView().GetPostItMgr()->Delete( pNoteItem->GetValue() );
334 break;
335 case FN_HIDE_NOTE:
336 if ( GetView().GetPostItMgr() && GetView().GetPostItMgr()->GetActivePostIt() )
337 GetView().GetPostItMgr()->GetActivePostIt()->Hide();
338 break;
339 case FN_HIDE_ALL_NOTES:
340 if ( GetView().GetPostItMgr() )
341 GetView().GetPostItMgr()->Hide();
342 break;
343 case FN_HIDE_NOTE_AUTHOR:
345 SFX_REQUEST_ARG( rReq, pNoteItem, SfxStringItem, nSlot, FALSE);
346 if ( pNoteItem && GetView().GetPostItMgr() )
347 GetView().GetPostItMgr()->Hide( pNoteItem->GetValue() );
349 break;
350 case FN_POSTIT:
352 SwPostItField* pPostIt = (SwPostItField*)aFldMgr.GetCurFld();
353 BOOL bNew = !(pPostIt && pPostIt->GetTyp()->Which() == RES_POSTITFLD);
354 if (bNew || GetView().GetPostItMgr()->IsAnswer())
356 SvtUserOptions aUserOpt;
357 String sAuthor;
358 if( !(sAuthor = aUserOpt.GetFullName()).Len())
359 if( !(sAuthor = aUserOpt.GetID()).Len() )
360 sAuthor = String( SW_RES( STR_REDLINE_UNKNOWN_AUTHOR ));
361 if( rSh.HasSelection() )
363 rSh.NormalizePam(true);
364 rSh.KillPams();
365 rSh.ClearMark();
367 SwInsertFld_Data aData(TYP_POSTITFLD, 0, sAuthor, aEmptyStr, 0);
368 aFldMgr.InsertFld(aData);
369 rSh.Push();
370 rSh.SwCrsrShell::Left(1, CRSR_SKIP_CHARS, FALSE);
371 pPostIt = (SwPostItField*)aFldMgr.GetCurFld();
372 rSh.Pop(FALSE); // Cursorpos restaurieren
375 if (pPostIt)
377 SwFieldType* pType = rSh.GetDoc()->GetFldType(RES_POSTITFLD, aEmptyStr,false);
378 SwClientIter aIter( *pType );
379 SwClient* pFirst = aIter.GoStart();
380 while( pFirst )
382 SwFmtFld* pSwFmtFld = static_cast<SwFmtFld*>(pFirst);
383 if ( pSwFmtFld->GetFld() == pPostIt )
385 pSwFmtFld->Broadcast( SwFmtFldHint( 0, SWFMTFLD_FOCUS, &GetView() ) );
386 break;
388 pFirst = aIter++;
392 break;
393 case FN_REDLINE_COMMENT:
395 /* this code can be used once we want redline comments in the margin, all other stuff can
396 then be deleted
397 String sComment;
398 const SwRedline *pRedline = rSh.GetCurrRedline();
400 if (pRedline)
402 sComment = pRedline->GetComment();
403 if ( sComment == String(rtl::OUString::createFromAscii("")) )
404 GetView().GetDocShell()->Broadcast(SwRedlineHint(pRedline,SWREDLINE_INSERTED));
405 const_cast<SwRedline*>(pRedline)->Broadcast(SwRedlineHint(pRedline,SWREDLINE_FOCUS,&GetView()));
409 String sComment;
410 const SwRedline *pRedline = rSh.GetCurrRedline();
412 if (pRedline)
414 sComment = pRedline->GetComment();
417 BOOL bTravel = FALSE;
419 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
420 DBG_ASSERT(pFact, "Dialogdiet fail!");
421 ::DialogGetRanges fnGetRange = pFact->GetDialogGetRangesFunc( RID_SVXDLG_POSTIT );
422 DBG_ASSERT(fnGetRange, "Dialogdiet fail! GetRanges()");
423 SfxItemSet aSet(GetPool(), fnGetRange());
424 aSet.Put(SvxPostItTextItem(sComment.ConvertLineEnd(), SID_ATTR_POSTIT_TEXT));
425 aSet.Put(SvxPostItAuthorItem(pRedline->GetAuthorString(), SID_ATTR_POSTIT_AUTHOR));
427 aSet.Put( SvxPostItDateItem( GetAppLangDateTimeString(
428 pRedline->GetRedlineData().GetTimeStamp() ),
429 SID_ATTR_POSTIT_DATE ));
431 // Traveling nur bei mehr als einem Feld
432 rSh.StartAction();
434 rSh.Push();
435 const SwRedline *pActRed = rSh.SelPrevRedline();
437 if (pActRed == pRedline)
438 { // Neuer Cursor steht am Anfang des Current Redlines
439 rSh.Pop(); // Alten Cursor wegwerfen
440 rSh.Push();
441 pActRed = rSh.SelPrevRedline();
444 BOOL bPrev = pActRed != 0;
445 rSh.Pop(FALSE);
446 rSh.EndAction();
448 rSh.ClearMark();
449 rSh.SelNextRedline(); // Aktueller Redline wird selektiert
451 rSh.StartAction();
452 rSh.Push();
453 pActRed = rSh.SelNextRedline();
454 BOOL bNext = pActRed != 0;
455 rSh.Pop(FALSE); // Cursorpos restaurieren
457 if( rSh.IsCrsrPtAtEnd() )
458 rSh.SwapPam();
460 rSh.EndAction();
462 bTravel |= bNext|bPrev;
464 SvxAbstractDialogFactory* pFact2 = SvxAbstractDialogFactory::Create();
465 DBG_ASSERT(pFact2, "Dialogdiet fail!");
466 AbstractSvxPostItDialog* pDlg = pFact2->CreateSvxPostItDialog( pMDI, aSet, RID_SVXDLG_POSTIT, bTravel, TRUE );
467 DBG_ASSERT(pDlg, "Dialogdiet fail!");
468 pDlg->HideAuthor();
470 String sTitle(SW_RES(STR_REDLINE_COMMENT));
471 ::lcl_AppendRedlineStr( sTitle, pRedline->GetType() );
473 pDlg->SetText(sTitle);
475 if (bTravel)
477 pDlg->EnableTravel(bNext, bPrev);
478 pDlg->SetPrevHdl(LINK(this, SwTextShell, RedlinePrevHdl));
479 pDlg->SetNextHdl(LINK(this, SwTextShell, RedlineNextHdl));
482 rSh.SetCareWin(pDlg->GetWindow());
483 bNoInterrupt = TRUE;
485 if ( pDlg->Execute() == RET_OK )
487 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
488 String sMsg(((const SvxPostItTextItem&)pOutSet->Get(SID_ATTR_POSTIT_TEXT)).GetValue());
490 // Kommentar einfuegen bzw aendern
491 rSh.SetRedlineComment(sMsg);
494 delete pDlg;
495 rSh.SetCareWin(NULL);
496 bNoInterrupt = FALSE;
497 rSh.ClearMark();
498 GetView().AttrChangedNotify(GetShellPtr());
501 break;
503 case FN_JAVAEDIT:
505 String aType, aText;
506 BOOL bIsUrl=FALSE;
507 BOOL bNew=FALSE, bUpdate=FALSE;
508 SwFldMgr* pMgr = new SwFldMgr;
509 if ( pItem )
511 aText = ((SfxStringItem*)pItem)->GetValue();
512 SFX_REQUEST_ARG( rReq, pType, SfxStringItem, FN_PARAM_2 , sal_False );
513 SFX_REQUEST_ARG( rReq, pIsUrl, SfxBoolItem, FN_PARAM_1 , sal_False );
514 if ( pType )
515 aType = pType->GetValue();
516 if ( pIsUrl )
517 bIsUrl = pIsUrl->GetValue();
519 SwScriptField* pFld = (SwScriptField*)pMgr->GetCurFld();
520 bNew = !pFld || !(pFld->GetTyp()->Which() == RES_SCRIPTFLD);
521 bUpdate = pFld && ( bIsUrl != pFld->GetFormat() || pFld->GetPar2() != aType || pFld->GetPar1() != aText );
523 else
525 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
526 DBG_ASSERT(pFact, "Dialogdiet fail!");
527 AbstractJavaEditDialog* pDlg = pFact->CreateJavaEditDialog( DLG_JAVAEDIT,
528 pMDI, &rSh);
529 DBG_ASSERT(pDlg, "Dialogdiet fail!");
530 if ( pDlg->Execute() )
532 aType = pDlg->GetType();
533 aText = pDlg->GetText();
534 bIsUrl = pDlg->IsUrl();
535 bNew = pDlg->IsNew();
536 bUpdate = pDlg->IsUpdate();
537 rReq.AppendItem( SfxStringItem( FN_JAVAEDIT, aText ) );
538 rReq.AppendItem( SfxStringItem( FN_PARAM_2, aType ) );
539 rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bIsUrl ) );
542 delete pDlg;
545 if( bNew )
547 SwInsertFld_Data aData(TYP_SCRIPTFLD, 0, aType, aText, bIsUrl);
548 pMgr->InsertFld(aData);
549 rReq.Done();
551 else if( bUpdate )
553 pMgr->UpdateCurFld( bIsUrl, aType, aText );
554 rSh.SetUndoNoResetModified();
555 rReq.Done();
557 else
558 rReq.Ignore();
560 break;
562 case FN_INSERT_FLD_DATE :
563 nInsertType = TYP_DATEFLD;
564 bIsText = FALSE;
565 goto FIELD_INSERT;
566 case FN_INSERT_FLD_TIME :
567 nInsertType = TYP_TIMEFLD;
568 bIsText = FALSE;
569 goto FIELD_INSERT;
570 case FN_INSERT_FLD_PGNUMBER:
571 nInsertType = TYP_PAGENUMBERFLD;
572 nInsertFormat = SVX_NUM_PAGEDESC; // wie Seitenvorlage
573 bIsText = FALSE;
574 goto FIELD_INSERT;
575 case FN_INSERT_FLD_PGCOUNT :
576 nInsertType = TYP_DOCSTATFLD;
577 nInsertSubType = 0;
578 bIsText = FALSE;
579 nInsertFormat = SVX_NUM_PAGEDESC;
580 goto FIELD_INSERT;
581 case FN_INSERT_FLD_TOPIC :
582 nInsertType = TYP_DOCINFOFLD;
583 nInsertSubType = DI_THEMA;
584 goto FIELD_INSERT;
585 case FN_INSERT_FLD_TITLE :
586 nInsertType = TYP_DOCINFOFLD;
587 nInsertSubType = DI_TITEL;
588 goto FIELD_INSERT;
589 case FN_INSERT_FLD_AUTHOR :
590 nInsertType = TYP_DOCINFOFLD;
591 nInsertSubType = DI_CREATE|DI_SUB_AUTHOR;
593 FIELD_INSERT:
595 //format conversion should only be done for number formatter formats
596 if(!nInsertFormat)
597 nInsertFormat = aFldMgr.GetDefaultFormat(nInsertType, bIsText, rSh.GetNumberFormatter());
598 SwInsertFld_Data aData(nInsertType, nInsertSubType,
599 aEmptyStr, aEmptyStr, nInsertFormat);
600 aFldMgr.InsertFld(aData);
601 rReq.Done();
603 break;
604 default:
605 ASSERT(FALSE, falscher Dispatcher);
606 return;
611 void SwTextShell::StateField( SfxItemSet &rSet )
613 SwWrtShell& rSh = GetShell();
614 SfxWhichIter aIter( rSet );
615 const SwField* pField = 0;
616 int bGetField = FALSE;
617 USHORT nWhich = aIter.FirstWhich();
619 while (nWhich)
621 switch (nWhich)
623 case FN_DELETE_NOTE:
624 case FN_DELETE_NOTE_AUTHOR:
625 case FN_DELETE_ALL_NOTES:
626 case FN_HIDE_NOTE:
627 case FN_HIDE_NOTE_AUTHOR:
628 case FN_HIDE_ALL_NOTES:
630 SwPostItMgr* pPostItMgr = GetView().GetPostItMgr();
631 if ( !pPostItMgr )
632 rSet.InvalidateItem( nWhich );
633 else if ( !pPostItMgr->GetActivePostIt() )
635 rSet.InvalidateItem( FN_DELETE_NOTE );
636 rSet.InvalidateItem( FN_HIDE_NOTE );
639 break;
640 case FN_EDIT_FIELD:
642 /* #108536# Fields can be selected, too now. Removed
644 if( rSh.HasSelection() )
645 rSet.DisableItem(nWhich);
646 else ...
649 if( !bGetField )
651 pField = rSh.GetCurFld();
652 bGetField = TRUE;
655 USHORT nTempWhich = pField ? pField->GetTyp()->Which() : USHRT_MAX;
656 if( USHRT_MAX == nTempWhich ||
657 RES_POSTITFLD == nTempWhich ||
658 RES_SCRIPTFLD == nTempWhich ||
659 RES_AUTHORITY == nTempWhich )
660 rSet.DisableItem( nWhich );
661 else if( RES_DDEFLD == nTempWhich &&
662 !((SwDDEFieldType*)pField->GetTyp())->GetBaseLink().IsVisible())
664 // nested links cannot be edited
665 rSet.DisableItem( nWhich );
668 break;
669 case FN_EXECUTE_MACROFIELD:
671 if(!bGetField)
673 pField = rSh.GetCurFld();
674 bGetField = TRUE;
676 if(!pField || pField->GetTyp()->Which() != RES_MACROFLD)
677 rSet.DisableItem(nWhich);
679 break;
681 case FN_INSERT_FIELD:
683 SfxViewFrame* pVFrame = GetView().GetViewFrame();
684 //#i5788# prevent closing of the field dialog while a modal dialog ( Input field dialog ) is active
685 if(!pVFrame->IsInModalMode() &&
686 pVFrame->KnowsChildWindow(FN_INSERT_FIELD) && !pVFrame->HasChildWindow(FN_INSERT_FIELD_DATA_ONLY) )
687 rSet.Put(SfxBoolItem( FN_INSERT_FIELD, pVFrame->HasChildWindow(nWhich)));
688 else
689 rSet.DisableItem(FN_INSERT_FIELD);
691 break;
692 case FN_INSERT_REF_FIELD:
694 SfxViewFrame* pVFrame = GetView().GetViewFrame();
695 if (!pVFrame->KnowsChildWindow(FN_INSERT_FIELD))
696 rSet.DisableItem(FN_INSERT_REF_FIELD);
698 break;
699 case FN_INSERT_FIELD_CTRL:
700 rSet.Put(SfxBoolItem( nWhich, GetView().GetViewFrame()->HasChildWindow(FN_INSERT_FIELD)));
701 break;
702 case FN_REDLINE_COMMENT:
703 if (!rSh.GetCurrRedline())
704 rSet.DisableItem(nWhich);
705 break;
706 case FN_POSTIT :
707 case FN_JAVAEDIT :
708 BOOL bCurField = FALSE;
709 pField = rSh.GetCurFld();
710 if(nWhich == FN_POSTIT)
711 bCurField = pField && pField->GetTyp()->Which() == RES_POSTITFLD;
712 else
713 bCurField = pField && pField->GetTyp()->Which() == RES_SCRIPTFLD;
715 if(!bCurField && rSh.IsReadOnlyAvailable() && rSh.HasReadonlySel() )
716 rSet.DisableItem(nWhich);
717 break;
719 nWhich = aIter.NextWhich();
723 /*---------------------------------------------------------------------------
724 Beschreibung:
725 ----------------------------------------------------------------------------*/
728 void SwTextShell::InsertHyperlink(const SvxHyperlinkItem& rHlnkItem)
730 const String& rName = rHlnkItem.GetName();
731 const String& rURL = rHlnkItem.GetURL();
732 const String& rTarget = rHlnkItem.GetTargetFrame();
733 USHORT nType = (USHORT)rHlnkItem.GetInsertMode();
734 nType &= ~HLINK_HTMLMODE;
735 const SvxMacroTableDtor* pMacroTbl = rHlnkItem.GetMacroTbl();
737 SwWrtShell& rSh = GetShell();
739 if( rSh.GetSelectionType() & nsSelectionType::SEL_TXT )
741 rSh.StartAction();
742 SfxItemSet aSet(GetPool(), RES_TXTATR_INETFMT, RES_TXTATR_INETFMT);
743 rSh.GetCurAttr( aSet );
745 const SfxPoolItem* pItem;
746 if(SFX_ITEM_SET == aSet.GetItemState(RES_TXTATR_INETFMT, FALSE, &pItem))
748 // Links selektieren
749 rSh.SwCrsrShell::SelectTxtAttr(RES_TXTATR_INETFMT, FALSE);
751 switch (nType)
753 case HLINK_DEFAULT:
754 case HLINK_FIELD:
756 SwFmtINetFmt aINetFmt( rURL, rTarget );
757 aINetFmt.SetName(rHlnkItem.GetIntName());
758 if(pMacroTbl)
760 SvxMacro *pMacro = pMacroTbl->Get( SFX_EVENT_MOUSEOVER_OBJECT );
761 if( pMacro )
762 aINetFmt.SetMacro(SFX_EVENT_MOUSEOVER_OBJECT, *pMacro);
763 pMacro = pMacroTbl->Get( SFX_EVENT_MOUSECLICK_OBJECT );
764 if( pMacro )
765 aINetFmt.SetMacro(SFX_EVENT_MOUSECLICK_OBJECT, *pMacro);
766 pMacro = pMacroTbl->Get( SFX_EVENT_MOUSEOUT_OBJECT );
767 if( pMacro )
768 aINetFmt.SetMacro(SFX_EVENT_MOUSEOUT_OBJECT, *pMacro);
770 rSh.SttSelect();
771 rSh.InsertURL( aINetFmt, rName, TRUE );
772 rSh.EndSelect();
774 break;
776 case HLINK_BUTTON:
777 BOOL bSel = rSh.HasSelection();
778 if(bSel)
779 rSh.DelRight();
780 InsertURLButton( rURL, rTarget, rName );
781 rSh.EnterStdMode();
782 break;
784 rSh.EndAction();
788 IMPL_LINK( SwTextShell, RedlineNextHdl, AbstractSvxPostItDialog *, pBtn )
790 SwWrtShell* pSh = GetShellPtr();
791 AbstractSvxPostItDialog *pDlg = (AbstractSvxPostItDialog*)pBtn;
793 // Kommentar einfuegen bzw aendern
794 pSh->SetRedlineComment(pDlg->GetNote());
796 const SwRedline *pRedline = pSh->GetCurrRedline();
798 String sComment;
800 if (pRedline)
802 // Traveling nur bei mehr als einem Feld
803 if( !pSh->IsCrsrPtAtEnd() )
804 pSh->SwapPam(); // Cursor hinter den Redline stellen
806 pSh->Push();
807 const SwRedline *pActRed = pSh->SelNextRedline();
808 pSh->Pop(pActRed != 0);
810 BOOL bEnable = FALSE;
812 if (pActRed)
814 pSh->StartAction();
815 pSh->Push();
816 bEnable = pSh->SelNextRedline() != 0;
817 pSh->Pop(FALSE);
818 pSh->EndAction();
821 pDlg->EnableTravel(bEnable, TRUE);
823 if( pSh->IsCrsrPtAtEnd() )
824 pSh->SwapPam();
826 pRedline = pSh->GetCurrRedline();
827 sComment = pRedline->GetComment();
829 pDlg->SetNote( sComment.ConvertLineEnd() );
830 pDlg->ShowLastAuthor( pRedline->GetAuthorString(),
831 GetAppLangDateTimeString(
832 pRedline->GetRedlineData().GetTimeStamp() ));
834 String sTitle(SW_RES(STR_REDLINE_COMMENT));
835 ::lcl_AppendRedlineStr( sTitle, pRedline->GetType() );
837 pDlg->SetText(sTitle);
840 return 0;
843 IMPL_LINK( SwTextShell, RedlinePrevHdl, AbstractSvxPostItDialog *, pBtn )
845 SwWrtShell* pSh = GetShellPtr();
846 AbstractSvxPostItDialog *pDlg = (AbstractSvxPostItDialog*)pBtn;
848 // Kommentar einfuegen bzw aendern
849 pSh->SetRedlineComment(pDlg->GetNote());
851 const SwRedline *pRedline = pSh->GetCurrRedline();
853 String sComment;
855 if (pRedline)
857 // Traveling nur bei mehr als einem Feld
858 pSh->Push();
859 const SwRedline *pActRed = pSh->SelPrevRedline();
860 pSh->Pop(pActRed != 0);
862 BOOL bEnable = FALSE;
864 if (pActRed)
866 pSh->StartAction();
867 pSh->Push();
868 bEnable = pSh->SelPrevRedline() != 0;
869 pSh->Pop(FALSE);
870 pSh->EndAction();
873 pDlg->EnableTravel(TRUE, bEnable);
875 pRedline = pSh->GetCurrRedline();
876 sComment = pRedline->GetComment();
878 pDlg->SetNote(sComment.ConvertLineEnd());
879 pDlg->ShowLastAuthor(pRedline->GetAuthorString(),
880 GetAppLangDateTimeString(
881 pRedline->GetRedlineData().GetTimeStamp() ));
883 String sTitle(SW_RES(STR_REDLINE_COMMENT));
884 ::lcl_AppendRedlineStr( sTitle, pRedline->GetType() );
886 pDlg->SetText(sTitle);
889 return 0;