bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / shells / textfld.cxx
blob87a66e517d901e94b5d73a9b0f1e9675ec1a753e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <crsskip.hxx>
22 #include <hintids.hxx> //_always_ before the solar-items
24 #include <sfx2/lnkbase.hxx>
25 #include <fmtfld.hxx>
26 #include <vcl/msgbox.hxx>
27 #include <svl/itempool.hxx>
28 #include <unotools/useroptions.hxx>
29 #include <svl/whiter.hxx>
30 #include <svl/eitem.hxx>
31 #include <svl/macitem.hxx>
32 #include <sfx2/viewfrm.hxx>
33 #include <sfx2/request.hxx>
34 #include <svx/postattr.hxx>
35 #include <svx/hlnkitem.hxx>
37 #include <svx/svxdlg.hxx>
38 #include <sfx2/linkmgr.hxx>
39 #include <unotools/localedatawrapper.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <fmtinfmt.hxx>
42 #include <fldwrap.hxx>
43 #include <redline.hxx>
44 #include <view.hxx>
45 #include <wrtsh.hxx>
46 #include <basesh.hxx>
47 #include <flddat.hxx>
48 #include <numrule.hxx>
49 #include <textsh.hxx>
50 #include <docsh.hxx>
51 #include <docufld.hxx>
52 #include <usrfld.hxx>
53 #include <ddefld.hxx>
54 #include <expfld.hxx>
55 #include <fldmgr.hxx>
56 #include <uitool.hxx>
58 #include <cmdid.h>
59 #include <shells.hrc>
61 #include <sfx2/app.hxx>
62 #include <svx/dialogs.hrc>
63 #include "swabstdlg.hxx"
64 #include "dialog.hrc"
65 #include <fldui.hrc>
66 #include <doc.hxx>
68 #include <app.hrc>
70 #include <PostItMgr.hxx>
71 #include <switerator.hxx>
73 using namespace nsSwDocInfoSubType;
75 extern bool bNoInterrupt; // in mainwn.cxx
77 static String& lcl_AppendRedlineStr( String& rStr, sal_uInt16 nRedlId )
79 sal_uInt16 nResId = 0;
80 switch( nRedlId )
82 case nsRedlineType_t::REDLINE_INSERT: nResId = STR_REDLINE_INSERTED; break;
83 case nsRedlineType_t::REDLINE_DELETE: nResId = STR_REDLINE_DELETED; break;
84 case nsRedlineType_t::REDLINE_FORMAT: nResId = STR_REDLINE_FORMATED; break;
85 case nsRedlineType_t::REDLINE_TABLE: nResId = STR_REDLINE_TABLECHG; break;
86 case nsRedlineType_t::REDLINE_FMTCOLL: nResId = STR_REDLINE_FMTCOLLSET; break;
88 if( nResId )
89 rStr += SW_RESSTR( nResId );
90 return rStr;
93 void SwTextShell::ExecField(SfxRequest &rReq)
95 SwWrtShell& rSh = GetShell();
96 const SfxPoolItem* pItem = 0;
98 sal_uInt16 nSlot = rReq.GetSlot();
99 const SfxItemSet* pArgs = rReq.GetArgs();
100 if(pArgs)
101 pArgs->GetItemState(GetPool().GetWhich(nSlot), sal_False, &pItem);
103 Window *pMDI = &GetView().GetViewFrame()->GetWindow();
104 bool bMore = false;
105 bool bIsText = true;
106 sal_uInt16 nInsertType = 0;
107 sal_uInt16 nInsertSubType = 0;
108 sal_uLong nInsertFormat = 0;
110 switch(nSlot)
112 case FN_EDIT_FIELD:
114 SwField* pFld = rSh.GetCurFld();
115 if( pFld )
117 switch ( pFld->GetTypeId() )
119 case TYP_DDEFLD:
121 ::sfx2::SvBaseLink& rLink = ((SwDDEFieldType*)pFld->GetTyp())->
122 GetBaseLink();
123 if(rLink.IsVisible())
125 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
126 SfxAbstractLinksDialog* pDlg = pFact->CreateLinksDialog( pMDI, &rSh.GetLinkManager(), sal_False, &rLink );
127 if ( pDlg )
129 pDlg->Execute();
130 delete pDlg;
133 break;
135 default:
137 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
138 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
140 SfxAbstractDialog* pDlg = pFact->CreateSwFldEditDlg( GetView(),RC_DLG_SWFLDEDITDLG );
141 OSL_ENSURE(pDlg, "Dialogdiet fail!");
142 pDlg->Execute();
143 delete pDlg;
147 break;
149 case FN_EXECUTE_MACROFIELD:
151 SwField* pFld = rSh.GetCurFld();
152 if(pFld && pFld->GetTyp()->Which() == RES_MACROFLD)
155 const String& rMacro = ((SwMacroField*)pFld)->GetMacro();
156 sal_uInt16 nPos = rMacro.Search('.', 0);
157 if(nPos != STRING_NOTFOUND)
159 SvxMacro aMacro( rMacro.Copy(nPos + 1), rMacro.Copy(0,nPos), STARBASIC );
160 rSh.ExecMacro(aMacro);
164 break;
166 case FN_GOTO_NEXT_INPUTFLD:
167 case FN_GOTO_PREV_INPUTFLD:
169 sal_Bool bRet = sal_False;
170 SwFieldType* pFld = rSh.GetFldType( 0, RES_INPUTFLD );
171 if( pFld && rSh.MoveFldType( pFld,
172 FN_GOTO_NEXT_INPUTFLD == nSlot ))
174 rSh.ClearMark();
175 rSh.StartInputFldDlg( rSh.GetCurFld(), sal_False );
176 bRet = sal_True;
179 rReq.SetReturnValue( SfxBoolItem( nSlot, bRet ));
181 break;
183 default:
184 bMore = true;
186 if(bMore)
188 // Here come the slots with FldMgr.
189 SwFldMgr aFldMgr(GetShellPtr());
190 switch(nSlot)
192 case FN_INSERT_DBFIELD:
194 sal_Bool bRes = sal_False;
195 if( pItem )
197 sal_uLong nFormat = 0;
198 sal_uInt16 nType = 0;
199 String aPar1 = ((SfxStringItem *)pItem)->GetValue();
200 String aPar2;
201 sal_Int32 nCommand = 0;
203 if( SFX_ITEM_SET == pArgs->GetItemState( FN_PARAM_FIELD_TYPE,
204 sal_False, &pItem ))
205 nType = ((SfxUInt16Item *)pItem)->GetValue();
206 aPar1 += DB_DELIM;
207 if( SFX_ITEM_SET == pArgs->GetItemState(
208 FN_PARAM_1, sal_False, &pItem ))
210 aPar1 += ((SfxStringItem *)pItem)->GetValue();
212 if( SFX_ITEM_SET == pArgs->GetItemState(
213 FN_PARAM_3, sal_False, &pItem ))
214 nCommand = ((SfxInt32Item*)pItem)->GetValue();
215 aPar1 += DB_DELIM;
216 aPar1 += OUString::number(nCommand);
217 aPar1 += DB_DELIM;
218 if( SFX_ITEM_SET == pArgs->GetItemState(
219 FN_PARAM_2, sal_False, &pItem ))
221 aPar1 += ((SfxStringItem *)pItem)->GetValue();
223 if( SFX_ITEM_SET == pArgs->GetItemState(
224 FN_PARAM_FIELD_CONTENT, sal_False, &pItem ))
225 aPar2 = ((SfxStringItem *)pItem)->GetValue();
226 if( SFX_ITEM_SET == pArgs->GetItemState(
227 FN_PARAM_FIELD_FORMAT, sal_False, &pItem ))
228 nFormat = ((SfxUInt32Item *)pItem)->GetValue();
229 OSL_FAIL("Command is not yet used");
230 sal_Unicode cSeparator = ' ';
231 SwInsertFld_Data aData(nType, 0, aPar1, aPar2, nFormat, GetShellPtr(), cSeparator );
232 bRes = aFldMgr.InsertFld(aData);
234 rReq.SetReturnValue(SfxBoolItem( nSlot, bRes ));
236 break;
237 case FN_INSERT_FIELD_CTRL:
238 case FN_INSERT_FIELD:
240 sal_Bool bRes = sal_False;
241 if( pItem && nSlot != FN_INSERT_FIELD_CTRL)
243 sal_uLong nFormat = 0;
244 sal_uInt16 nType = 0;
245 sal_uInt16 nSubType = 0;
246 String aPar1 = ((SfxStringItem *)pItem)->GetValue();
247 String aPar2;
248 sal_Unicode cSeparator = ' ';
250 if( SFX_ITEM_SET == pArgs->GetItemState( FN_PARAM_FIELD_TYPE,
251 sal_False, &pItem ))
252 nType = ((SfxUInt16Item *)pItem)->GetValue();
253 if( SFX_ITEM_SET == pArgs->GetItemState( FN_PARAM_FIELD_SUBTYPE,
254 sal_False, &pItem ))
255 nSubType = ((SfxUInt16Item *)pItem)->GetValue();
256 if( SFX_ITEM_SET == pArgs->GetItemState(
257 FN_PARAM_FIELD_CONTENT, sal_False, &pItem ))
258 aPar2 = ((SfxStringItem *)pItem)->GetValue();
259 if( SFX_ITEM_SET == pArgs->GetItemState(
260 FN_PARAM_FIELD_FORMAT, sal_False, &pItem ))
261 nFormat = ((SfxUInt32Item *)pItem)->GetValue();
262 if( SFX_ITEM_SET == pArgs->GetItemState(
263 FN_PARAM_3, sal_False, &pItem ))
265 String sTmp = ((SfxStringItem *)pItem)->GetValue();
266 if(sTmp.Len())
267 cSeparator = sTmp.GetChar(0);
269 SwInsertFld_Data aData(nType, nSubType, aPar1, aPar2, nFormat, GetShellPtr(), cSeparator );
270 bRes = aFldMgr.InsertFld( aData );
272 else
273 //#i5788# prevent closing of the field dialog while a modal dialog ( Input field dialog ) is active
274 if(!GetView().GetViewFrame()->IsInModalMode())
276 SfxViewFrame* pVFrame = GetView().GetViewFrame();
277 pVFrame->ToggleChildWindow(FN_INSERT_FIELD);
278 bRes = pVFrame->GetChildWindow( nSlot ) != 0;
279 Invalidate(rReq.GetSlot());
280 Invalidate(FN_INSERT_FIELD_CTRL);
281 rReq.Ignore();
283 rReq.SetReturnValue(SfxBoolItem( nSlot, bRes ));
285 break;
287 case FN_INSERT_REF_FIELD:
289 SfxViewFrame* pVFrame = GetView().GetViewFrame();
290 if (!pVFrame->HasChildWindow(FN_INSERT_FIELD))
291 pVFrame->ToggleChildWindow(FN_INSERT_FIELD); // Show dialog
293 // Switch Flddlg at a new TabPage
294 sal_uInt16 nId = SwFldDlgWrapper::GetChildWindowId();
295 SwFldDlgWrapper *pWrp = (SwFldDlgWrapper*)pVFrame->GetChildWindow(nId);
296 if (pWrp)
297 pWrp->ShowPage();
298 rReq.Ignore();
300 break;
301 case FN_DELETE_COMMENT:
302 if ( GetView().GetPostItMgr() &&
303 GetView().GetPostItMgr()->HasActiveSidebarWin() )
305 GetView().GetPostItMgr()->DeleteActiveSidebarWin();
307 break;
308 case FN_DELETE_ALL_NOTES:
309 if ( GetView().GetPostItMgr() )
310 GetView().GetPostItMgr()->Delete();
311 break;
312 case FN_DELETE_NOTE_AUTHOR:
314 SFX_REQUEST_ARG( rReq, pNoteItem, SfxStringItem, nSlot, sal_False);
315 if ( pNoteItem && GetView().GetPostItMgr() )
316 GetView().GetPostItMgr()->Delete( pNoteItem->GetValue() );
318 break;
319 case FN_HIDE_NOTE:
320 if ( GetView().GetPostItMgr() &&
321 GetView().GetPostItMgr()->HasActiveSidebarWin() )
323 GetView().GetPostItMgr()->HideActiveSidebarWin();
325 break;
326 case FN_HIDE_ALL_NOTES:
327 if ( GetView().GetPostItMgr() )
328 GetView().GetPostItMgr()->Hide();
329 break;
330 case FN_HIDE_NOTE_AUTHOR:
332 SFX_REQUEST_ARG( rReq, pNoteItem, SfxStringItem, nSlot, sal_False);
333 if ( pNoteItem && GetView().GetPostItMgr() )
334 GetView().GetPostItMgr()->Hide( pNoteItem->GetValue() );
336 break;
337 case FN_POSTIT:
339 SwPostItField* pPostIt = (SwPostItField*)aFldMgr.GetCurFld();
340 bool bNew = !(pPostIt && pPostIt->GetTyp()->Which() == RES_POSTITFLD);
341 if (bNew || GetView().GetPostItMgr()->IsAnswer())
343 SvtUserOptions aUserOpt;
344 String sAuthor;
345 if( !(sAuthor = aUserOpt.GetFullName()).Len())
346 if( !(sAuthor = aUserOpt.GetID()).Len() )
347 sAuthor = String( SW_RES( STR_REDLINE_UNKNOWN_AUTHOR ));
349 // Save the current selection, it will be required later for fieldmark insertion.
350 SwPaM& rCurrPam = rSh.GetCurrentShellCursor();
351 SwPaM aSaved(*rCurrPam.GetPoint(), *rCurrPam.GetMark());
352 if( rSh.HasSelection() )
354 rSh.NormalizePam(false);
355 rSh.KillPams();
356 rSh.ClearMark();
358 SwInsertFld_Data aData(TYP_POSTITFLD, 0, sAuthor, aEmptyStr, 0);
359 aFldMgr.InsertFld(aData, &aSaved);
361 rSh.Push();
362 rSh.SwCrsrShell::Left(1, CRSR_SKIP_CHARS, sal_False);
363 pPostIt = (SwPostItField*)aFldMgr.GetCurFld();
364 rSh.Pop(sal_False); // Restore cursor position
367 if (pPostIt)
369 SwFieldType* pType = rSh.GetDoc()->GetFldType(RES_POSTITFLD, aEmptyStr,false);
370 SwIterator<SwFmtFld,SwFieldType> aIter( *pType );
371 SwFmtFld* pSwFmtFld = aIter.First();
372 while( pSwFmtFld )
374 if ( pSwFmtFld->GetFld() == pPostIt )
376 pSwFmtFld->Broadcast( SwFmtFldHint( 0, SWFMTFLD_FOCUS, &GetView() ) );
377 break;
379 pSwFmtFld = aIter.Next();
383 break;
384 case FN_REDLINE_COMMENT:
386 /* this code can be used once we want redline comments in the margin, all other stuff can
387 then be deleted
388 String sComment;
389 const SwRedline *pRedline = rSh.GetCurrRedline();
391 if (pRedline)
393 sComment = pRedline->GetComment();
394 if ( !sComment.Len() )
395 GetView().GetDocShell()->Broadcast(SwRedlineHint(pRedline,SWREDLINE_INSERTED));
396 const_cast<SwRedline*>(pRedline)->Broadcast(SwRedlineHint(pRedline,SWREDLINE_FOCUS,&GetView()));
400 const SwRedline *pRedline = rSh.GetCurrRedline();
402 if (pRedline)
404 OUString sComment = convertLineEnd(pRedline->GetComment(), GetSystemLineEnd());
406 sal_Bool bTravel = sal_False;
408 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
409 OSL_ENSURE(pFact, "Dialogdiet fail!");
410 ::DialogGetRanges fnGetRange = pFact->GetDialogGetRangesFunc();
411 OSL_ENSURE(fnGetRange, "Dialogdiet fail! GetRanges()");
412 SfxItemSet aSet(GetPool(), fnGetRange());
413 aSet.Put(SvxPostItTextItem(sComment, SID_ATTR_POSTIT_TEXT));
414 aSet.Put(SvxPostItAuthorItem(pRedline->GetAuthorString(), SID_ATTR_POSTIT_AUTHOR));
416 aSet.Put( SvxPostItDateItem( GetAppLangDateTimeString(
417 pRedline->GetRedlineData().GetTimeStamp() ),
418 SID_ATTR_POSTIT_DATE ));
420 // Traveling only if more than one field.
421 rSh.StartAction();
423 rSh.Push();
424 const SwRedline *pActRed = rSh.SelPrevRedline();
426 if (pActRed == pRedline)
427 { // New cursor is at the beginning of the current redlines.
428 rSh.Pop(); // Throw old cursor away
429 rSh.Push();
430 pActRed = rSh.SelPrevRedline();
433 sal_Bool bPrev = pActRed != 0;
434 rSh.Pop(sal_False);
435 rSh.EndAction();
437 rSh.ClearMark();
438 rSh.SelNextRedline(); // Select current redline.
440 rSh.StartAction();
441 rSh.Push();
442 pActRed = rSh.SelNextRedline();
443 sal_Bool bNext = pActRed != 0;
444 rSh.Pop(sal_False); // Restore cursor position
446 if( rSh.IsCrsrPtAtEnd() )
447 rSh.SwapPam();
449 rSh.EndAction();
451 bTravel |= bNext|bPrev;
453 SvxAbstractDialogFactory* pFact2 = SvxAbstractDialogFactory::Create();
454 OSL_ENSURE(pFact2, "Dialogdiet fail!");
455 AbstractSvxPostItDialog* pDlg = pFact2->CreateSvxPostItDialog( pMDI, aSet, bTravel );
456 OSL_ENSURE(pDlg, "Dialogdiet fail!");
457 pDlg->HideAuthor();
459 String sTitle(SW_RES(STR_REDLINE_COMMENT));
460 ::lcl_AppendRedlineStr( sTitle, pRedline->GetType() );
462 pDlg->SetText(sTitle);
464 if (bTravel)
466 pDlg->EnableTravel(bNext, bPrev);
467 pDlg->SetPrevHdl(LINK(this, SwTextShell, RedlinePrevHdl));
468 pDlg->SetNextHdl(LINK(this, SwTextShell, RedlineNextHdl));
471 rSh.SetCareWin(pDlg->GetWindow());
472 bNoInterrupt = true;
474 if ( pDlg->Execute() == RET_OK )
476 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
477 String sMsg(((const SvxPostItTextItem&)pOutSet->Get(SID_ATTR_POSTIT_TEXT)).GetValue());
479 // Insert or change a comment
480 rSh.SetRedlineComment(sMsg);
483 delete pDlg;
484 rSh.SetCareWin(NULL);
485 bNoInterrupt = false;
486 rSh.ClearMark();
487 GetView().AttrChangedNotify(GetShellPtr());
490 break;
492 case FN_JAVAEDIT:
494 OUString aType, aText;
495 sal_Bool bIsUrl=sal_False;
496 sal_Bool bNew=sal_False;
497 bool bUpdate = false;
498 SwFldMgr* pMgr = new SwFldMgr;
499 if ( pItem )
501 aText = ((SfxStringItem*)pItem)->GetValue();
502 SFX_REQUEST_ARG( rReq, pType, SfxStringItem, FN_PARAM_2 , sal_False );
503 SFX_REQUEST_ARG( rReq, pIsUrl, SfxBoolItem, FN_PARAM_1 , sal_False );
504 if ( pType )
505 aType = pType->GetValue();
506 if ( pIsUrl )
507 bIsUrl = pIsUrl->GetValue();
509 SwScriptField* pFld = (SwScriptField*)pMgr->GetCurFld();
510 bNew = !pFld || !(pFld->GetTyp()->Which() == RES_SCRIPTFLD);
511 bUpdate = pFld && ( bIsUrl != pFld->GetFormat() || pFld->GetPar2() != aType || pFld->GetPar1() != aText );
513 else
515 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
516 OSL_ENSURE(pFact, "Dialogdiet fail!");
517 AbstractJavaEditDialog* pDlg = pFact->CreateJavaEditDialog(pMDI, &rSh);
518 OSL_ENSURE(pDlg, "Dialogdiet fail!");
519 if ( pDlg->Execute() )
521 aType = pDlg->GetType();
522 aText = pDlg->GetText();
523 bIsUrl = pDlg->IsUrl();
524 bNew = pDlg->IsNew();
525 bUpdate = pDlg->IsUpdate();
526 rReq.AppendItem( SfxStringItem( FN_JAVAEDIT, aText ) );
527 rReq.AppendItem( SfxStringItem( FN_PARAM_2, aType ) );
528 rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bIsUrl ) );
531 delete pDlg;
534 if( bNew )
536 SwInsertFld_Data aData(TYP_SCRIPTFLD, 0, aType, aText, bIsUrl);
537 pMgr->InsertFld(aData);
538 rReq.Done();
540 else if( bUpdate )
542 pMgr->UpdateCurFld( bIsUrl, aType, aText );
543 rSh.SetUndoNoResetModified();
544 rReq.Done();
546 else
547 rReq.Ignore();
549 break;
551 case FN_INSERT_FLD_DATE :
552 nInsertType = TYP_DATEFLD;
553 bIsText = false;
554 goto FIELD_INSERT;
555 case FN_INSERT_FLD_TIME :
556 nInsertType = TYP_TIMEFLD;
557 bIsText = false;
558 goto FIELD_INSERT;
559 case FN_INSERT_FLD_PGNUMBER:
560 nInsertType = TYP_PAGENUMBERFLD;
561 nInsertFormat = SVX_NUM_PAGEDESC; // Like page template
562 bIsText = false;
563 goto FIELD_INSERT;
564 case FN_INSERT_FLD_PGCOUNT :
565 nInsertType = TYP_DOCSTATFLD;
566 nInsertSubType = 0;
567 bIsText = false;
568 nInsertFormat = SVX_NUM_PAGEDESC;
569 goto FIELD_INSERT;
570 case FN_INSERT_FLD_TOPIC :
571 nInsertType = TYP_DOCINFOFLD;
572 nInsertSubType = DI_THEMA;
573 goto FIELD_INSERT;
574 case FN_INSERT_FLD_TITLE :
575 nInsertType = TYP_DOCINFOFLD;
576 nInsertSubType = DI_TITEL;
577 goto FIELD_INSERT;
578 case FN_INSERT_FLD_AUTHOR :
579 nInsertType = TYP_DOCINFOFLD;
580 nInsertSubType = DI_CREATE|DI_SUB_AUTHOR;
582 FIELD_INSERT:
584 //format conversion should only be done for number formatter formats
585 if(!nInsertFormat)
586 nInsertFormat = aFldMgr.GetDefaultFormat(nInsertType, bIsText, rSh.GetNumberFormatter());
587 SwInsertFld_Data aData(nInsertType, nInsertSubType,
588 aEmptyStr, aEmptyStr, nInsertFormat);
589 aFldMgr.InsertFld(aData);
590 rReq.Done();
592 break;
593 default:
594 OSL_FAIL("wrong dispatcher");
595 return;
600 void SwTextShell::StateField( SfxItemSet &rSet )
602 SwWrtShell& rSh = GetShell();
603 SfxWhichIter aIter( rSet );
604 const SwField* pField = 0;
605 int bGetField = sal_False;
606 sal_uInt16 nWhich = aIter.FirstWhich();
608 while (nWhich)
610 switch (nWhich)
612 case FN_DELETE_COMMENT:
613 case FN_DELETE_NOTE_AUTHOR:
614 case FN_DELETE_ALL_NOTES:
615 case FN_HIDE_NOTE:
616 case FN_HIDE_NOTE_AUTHOR:
617 case FN_HIDE_ALL_NOTES:
619 SwPostItMgr* pPostItMgr = GetView().GetPostItMgr();
620 if ( !pPostItMgr )
621 rSet.InvalidateItem( nWhich );
622 else if ( !pPostItMgr->HasActiveSidebarWin() )
624 rSet.InvalidateItem( FN_DELETE_COMMENT );
625 rSet.InvalidateItem( FN_HIDE_NOTE );
628 break;
629 case FN_EDIT_FIELD:
632 if( !bGetField )
634 pField = rSh.GetCurFld();
635 bGetField = sal_True;
638 sal_uInt16 nTempWhich = pField ? pField->GetTyp()->Which() : USHRT_MAX;
639 if( USHRT_MAX == nTempWhich ||
640 RES_POSTITFLD == nTempWhich ||
641 RES_SCRIPTFLD == nTempWhich ||
642 RES_AUTHORITY == nTempWhich )
643 rSet.DisableItem( nWhich );
644 else if( RES_DDEFLD == nTempWhich &&
645 !((SwDDEFieldType*)pField->GetTyp())->GetBaseLink().IsVisible())
647 // nested links cannot be edited
648 rSet.DisableItem( nWhich );
651 break;
652 case FN_EXECUTE_MACROFIELD:
654 if(!bGetField)
656 pField = rSh.GetCurFld();
657 bGetField = sal_True;
659 if(!pField || pField->GetTyp()->Which() != RES_MACROFLD)
660 rSet.DisableItem(nWhich);
662 break;
664 case FN_INSERT_FIELD:
666 SfxViewFrame* pVFrame = GetView().GetViewFrame();
667 //#i5788# prevent closing of the field dialog while a modal dialog ( Input field dialog ) is active
668 if(!pVFrame->IsInModalMode() &&
669 pVFrame->KnowsChildWindow(FN_INSERT_FIELD) && !pVFrame->HasChildWindow(FN_INSERT_FIELD_DATA_ONLY) )
670 rSet.Put(SfxBoolItem( FN_INSERT_FIELD, pVFrame->HasChildWindow(nWhich)));
671 else
672 rSet.DisableItem(FN_INSERT_FIELD);
674 break;
675 case FN_INSERT_REF_FIELD:
677 SfxViewFrame* pVFrame = GetView().GetViewFrame();
678 if (!pVFrame->KnowsChildWindow(FN_INSERT_FIELD))
679 rSet.DisableItem(FN_INSERT_REF_FIELD);
681 break;
682 case FN_INSERT_FIELD_CTRL:
683 rSet.Put(SfxBoolItem( nWhich, GetView().GetViewFrame()->HasChildWindow(FN_INSERT_FIELD)));
684 break;
685 case FN_REDLINE_COMMENT:
686 if (!rSh.GetCurrRedline())
687 rSet.DisableItem(nWhich);
688 break;
689 case FN_POSTIT :
690 case FN_JAVAEDIT :
691 bool bCurField = false;
692 pField = rSh.GetCurFld();
693 if(nWhich == FN_POSTIT)
694 bCurField = pField && pField->GetTyp()->Which() == RES_POSTITFLD;
695 else
696 bCurField = pField && pField->GetTyp()->Which() == RES_SCRIPTFLD;
698 if(!bCurField && rSh.IsReadOnlyAvailable() && rSh.HasReadonlySel() )
699 rSet.DisableItem(nWhich);
700 break;
702 nWhich = aIter.NextWhich();
706 void SwTextShell::InsertHyperlink(const SvxHyperlinkItem& rHlnkItem)
708 const String& rName = rHlnkItem.GetName();
709 const String& rURL = rHlnkItem.GetURL();
710 const String& rTarget = rHlnkItem.GetTargetFrame();
711 sal_uInt16 nType = (sal_uInt16)rHlnkItem.GetInsertMode();
712 nType &= ~HLINK_HTMLMODE;
713 const SvxMacroTableDtor* pMacroTbl = rHlnkItem.GetMacroTbl();
715 SwWrtShell& rSh = GetShell();
717 if( rSh.GetSelectionType() & nsSelectionType::SEL_TXT )
719 rSh.StartAction();
720 SfxItemSet aSet(GetPool(), RES_TXTATR_INETFMT, RES_TXTATR_INETFMT);
721 rSh.GetCurAttr( aSet );
723 const SfxPoolItem* pItem;
724 if(SFX_ITEM_SET == aSet.GetItemState(RES_TXTATR_INETFMT, sal_False, &pItem))
726 // Select links
727 rSh.SwCrsrShell::SelectTxtAttr(RES_TXTATR_INETFMT, sal_False);
729 switch (nType)
731 case HLINK_DEFAULT:
732 case HLINK_FIELD:
734 SwFmtINetFmt aINetFmt( rURL, rTarget );
735 aINetFmt.SetName(rHlnkItem.GetIntName());
736 if(pMacroTbl)
738 const SvxMacro *pMacro = pMacroTbl->Get( SFX_EVENT_MOUSEOVER_OBJECT );
739 if( pMacro )
740 aINetFmt.SetMacro(SFX_EVENT_MOUSEOVER_OBJECT, *pMacro);
741 pMacro = pMacroTbl->Get( SFX_EVENT_MOUSECLICK_OBJECT );
742 if( pMacro )
743 aINetFmt.SetMacro(SFX_EVENT_MOUSECLICK_OBJECT, *pMacro);
744 pMacro = pMacroTbl->Get( SFX_EVENT_MOUSEOUT_OBJECT );
745 if( pMacro )
746 aINetFmt.SetMacro(SFX_EVENT_MOUSEOUT_OBJECT, *pMacro);
748 rSh.SttSelect();
749 rSh.InsertURL( aINetFmt, rName, sal_True );
750 rSh.EndSelect();
752 break;
754 case HLINK_BUTTON:
755 sal_Bool bSel = rSh.HasSelection();
756 if(bSel)
757 rSh.DelRight();
758 InsertURLButton( rURL, rTarget, rName );
759 rSh.EnterStdMode();
760 break;
762 rSh.EndAction();
766 IMPL_LINK( SwTextShell, RedlineNextHdl, AbstractSvxPostItDialog *, pBtn )
768 SwWrtShell* pSh = GetShellPtr();
769 AbstractSvxPostItDialog *pDlg = (AbstractSvxPostItDialog*)pBtn;
771 // Insert or change a comment.
772 pSh->SetRedlineComment(pDlg->GetNote());
774 const SwRedline *pRedline = pSh->GetCurrRedline();
776 if (pRedline)
778 // Traveling only if more than one field.
779 if( !pSh->IsCrsrPtAtEnd() )
780 pSh->SwapPam(); // Move the cursor behind the Redline.
782 pSh->Push();
783 const SwRedline *pActRed = pSh->SelNextRedline();
784 pSh->Pop(pActRed != 0);
786 sal_Bool bEnable = sal_False;
788 if (pActRed)
790 pSh->StartAction();
791 pSh->Push();
792 bEnable = pSh->SelNextRedline() != 0;
793 pSh->Pop(sal_False);
794 pSh->EndAction();
797 pDlg->EnableTravel(bEnable, sal_True);
799 if( pSh->IsCrsrPtAtEnd() )
800 pSh->SwapPam();
802 pRedline = pSh->GetCurrRedline();
803 OUString sComment = convertLineEnd(pRedline->GetComment(), GetSystemLineEnd());
805 pDlg->SetNote(sComment);
806 pDlg->ShowLastAuthor( pRedline->GetAuthorString(),
807 GetAppLangDateTimeString(
808 pRedline->GetRedlineData().GetTimeStamp() ));
810 String sTitle(SW_RES(STR_REDLINE_COMMENT));
811 ::lcl_AppendRedlineStr( sTitle, pRedline->GetType() );
813 pDlg->SetText(sTitle);
816 return 0;
819 IMPL_LINK( SwTextShell, RedlinePrevHdl, AbstractSvxPostItDialog *, pBtn )
821 SwWrtShell* pSh = GetShellPtr();
822 AbstractSvxPostItDialog *pDlg = (AbstractSvxPostItDialog*)pBtn;
824 // Insert or change a comment.
825 pSh->SetRedlineComment(pDlg->GetNote());
827 const SwRedline *pRedline = pSh->GetCurrRedline();
829 if (pRedline)
831 // Traveling only if more than one field.
832 pSh->Push();
833 const SwRedline *pActRed = pSh->SelPrevRedline();
834 pSh->Pop(pActRed != 0);
836 sal_Bool bEnable = sal_False;
838 if (pActRed)
840 pSh->StartAction();
841 pSh->Push();
842 bEnable = pSh->SelPrevRedline() != 0;
843 pSh->Pop(sal_False);
844 pSh->EndAction();
847 pDlg->EnableTravel(sal_True, bEnable);
849 pRedline = pSh->GetCurrRedline();
850 OUString sComment = convertLineEnd(pRedline->GetComment(), GetSystemLineEnd());
852 pDlg->SetNote(sComment);
853 pDlg->ShowLastAuthor(pRedline->GetAuthorString(),
854 GetAppLangDateTimeString(
855 pRedline->GetRedlineData().GetTimeStamp() ));
857 String sTitle(SW_RES(STR_REDLINE_COMMENT));
858 ::lcl_AppendRedlineStr( sTitle, pRedline->GetType() );
860 pDlg->SetText(sTitle);
863 return 0;
866 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */