Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <crsskip.hxx>
22 : #include <hintids.hxx> //_always_ before the solar-items
23 :
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>
36 : #include <svx/svxdlg.hxx>
37 : #include <sfx2/linkmgr.hxx>
38 : #include <unotools/localedatawrapper.hxx>
39 : #include <sfx2/dispatch.hxx>
40 : #include <fmtinfmt.hxx>
41 : #include <fldwrap.hxx>
42 : #include <redline.hxx>
43 : #include <view.hxx>
44 : #include <wrtsh.hxx>
45 : #include <basesh.hxx>
46 : #include <flddat.hxx>
47 : #include <numrule.hxx>
48 : #include <textsh.hxx>
49 : #include <docsh.hxx>
50 : #include <docufld.hxx>
51 : #include <usrfld.hxx>
52 : #include <ddefld.hxx>
53 : #include <expfld.hxx>
54 : #include <fldmgr.hxx>
55 : #include <uitool.hxx>
56 : #include <cmdid.h>
57 : #include <shells.hrc>
58 : #include <sfx2/app.hxx>
59 : #include <svx/dialogs.hrc>
60 : #include "swabstdlg.hxx"
61 : #include "dialog.hrc"
62 : #include <fldui.hrc>
63 : #include <doc.hxx>
64 : #include <app.hrc>
65 : #include <edtwin.hxx>
66 : #include <PostItMgr.hxx>
67 : #include <switerator.hxx>
68 :
69 : using namespace nsSwDocInfoSubType;
70 :
71 : extern bool bNoInterrupt; // in mainwn.cxx
72 :
73 0 : static String& lcl_AppendRedlineStr( String& rStr, sal_uInt16 nRedlId )
74 : {
75 0 : sal_uInt16 nResId = 0;
76 0 : switch( nRedlId )
77 : {
78 0 : case nsRedlineType_t::REDLINE_INSERT: nResId = STR_REDLINE_INSERTED; break;
79 0 : case nsRedlineType_t::REDLINE_DELETE: nResId = STR_REDLINE_DELETED; break;
80 0 : case nsRedlineType_t::REDLINE_FORMAT: nResId = STR_REDLINE_FORMATED; break;
81 0 : case nsRedlineType_t::REDLINE_TABLE: nResId = STR_REDLINE_TABLECHG; break;
82 0 : case nsRedlineType_t::REDLINE_FMTCOLL: nResId = STR_REDLINE_FMTCOLLSET; break;
83 : }
84 0 : if( nResId )
85 0 : rStr += SW_RESSTR( nResId );
86 0 : return rStr;
87 : }
88 :
89 0 : void SwTextShell::ExecField(SfxRequest &rReq)
90 : {
91 0 : SwWrtShell& rSh = GetShell();
92 0 : const SfxPoolItem* pItem = 0;
93 :
94 0 : sal_uInt16 nSlot = rReq.GetSlot();
95 0 : const SfxItemSet* pArgs = rReq.GetArgs();
96 0 : if(pArgs)
97 0 : pArgs->GetItemState(GetPool().GetWhich(nSlot), sal_False, &pItem);
98 :
99 0 : Window *pMDI = &GetView().GetViewFrame()->GetWindow();
100 0 : bool bMore = false;
101 0 : bool bIsText = true;
102 0 : sal_uInt16 nInsertType = 0;
103 0 : sal_uInt16 nInsertSubType = 0;
104 0 : sal_uLong nInsertFormat = 0;
105 :
106 0 : switch(nSlot)
107 : {
108 : case FN_EDIT_FIELD:
109 : {
110 0 : SwField* pFld = rSh.GetCurFld();
111 0 : if( pFld )
112 : {
113 0 : switch ( pFld->GetTypeId() )
114 : {
115 : case TYP_DDEFLD:
116 : {
117 0 : ::sfx2::SvBaseLink& rLink = ((SwDDEFieldType*)pFld->GetTyp())->
118 0 : GetBaseLink();
119 0 : if(rLink.IsVisible())
120 : {
121 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
122 0 : SfxAbstractLinksDialog* pDlg = pFact->CreateLinksDialog( pMDI, &rSh.GetLinkManager(), sal_False, &rLink );
123 0 : if ( pDlg )
124 : {
125 0 : pDlg->Execute();
126 0 : delete pDlg;
127 : }
128 : }
129 0 : break;
130 : }
131 : default:
132 : {
133 0 : SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
134 : OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
135 :
136 0 : SfxAbstractDialog* pDlg = pFact->CreateSwFldEditDlg( GetView(),RC_DLG_SWFLDEDITDLG );
137 : OSL_ENSURE(pDlg, "Dialogdiet fail!");
138 0 : pDlg->Execute();
139 0 : delete pDlg;
140 : }
141 : }
142 : }
143 0 : break;
144 : }
145 : case FN_EXECUTE_MACROFIELD:
146 : {
147 0 : SwField* pFld = rSh.GetCurFld();
148 0 : if(pFld && pFld->GetTyp()->Which() == RES_MACROFLD)
149 : {
150 :
151 0 : const String& rMacro = ((SwMacroField*)pFld)->GetMacro();
152 0 : sal_uInt16 nPos = rMacro.Search('.', 0);
153 0 : if(nPos != STRING_NOTFOUND)
154 : {
155 0 : SvxMacro aMacro( rMacro.Copy(nPos + 1), rMacro.Copy(0,nPos), STARBASIC );
156 0 : rSh.ExecMacro(aMacro);
157 0 : }
158 : }
159 : }
160 0 : break;
161 :
162 : case FN_GOTO_NEXT_INPUTFLD:
163 : case FN_GOTO_PREV_INPUTFLD:
164 : {
165 0 : sal_Bool bRet = sal_False;
166 0 : SwFieldType* pFld = rSh.GetFldType( 0, RES_INPUTFLD );
167 0 : if( pFld && rSh.MoveFldType( pFld,
168 0 : FN_GOTO_NEXT_INPUTFLD == nSlot ))
169 : {
170 0 : rSh.ClearMark();
171 0 : rSh.StartInputFldDlg( rSh.GetCurFld(), sal_False );
172 0 : bRet = sal_True;
173 : }
174 :
175 0 : rReq.SetReturnValue( SfxBoolItem( nSlot, bRet ));
176 : }
177 0 : break;
178 :
179 : default:
180 0 : bMore = true;
181 : }
182 0 : if(bMore)
183 : {
184 : // Here come the slots with FldMgr.
185 0 : SwFldMgr aFldMgr(GetShellPtr());
186 0 : switch(nSlot)
187 : {
188 : case FN_INSERT_DBFIELD:
189 : {
190 0 : sal_Bool bRes = sal_False;
191 0 : if( pItem )
192 : {
193 0 : sal_uLong nFormat = 0;
194 0 : sal_uInt16 nType = 0;
195 0 : String aPar1 = ((SfxStringItem *)pItem)->GetValue();
196 0 : String aPar2;
197 0 : sal_Int32 nCommand = 0;
198 :
199 0 : if( SFX_ITEM_SET == pArgs->GetItemState( FN_PARAM_FIELD_TYPE,
200 0 : sal_False, &pItem ))
201 0 : nType = ((SfxUInt16Item *)pItem)->GetValue();
202 0 : aPar1 += DB_DELIM;
203 0 : if( SFX_ITEM_SET == pArgs->GetItemState(
204 0 : FN_PARAM_1, sal_False, &pItem ))
205 : {
206 0 : aPar1 += ((SfxStringItem *)pItem)->GetValue();
207 : }
208 0 : if( SFX_ITEM_SET == pArgs->GetItemState(
209 0 : FN_PARAM_3, sal_False, &pItem ))
210 0 : nCommand = ((SfxInt32Item*)pItem)->GetValue();
211 0 : aPar1 += DB_DELIM;
212 0 : aPar1 += OUString::number(nCommand);
213 0 : aPar1 += DB_DELIM;
214 0 : if( SFX_ITEM_SET == pArgs->GetItemState(
215 0 : FN_PARAM_2, sal_False, &pItem ))
216 : {
217 0 : aPar1 += ((SfxStringItem *)pItem)->GetValue();
218 : }
219 0 : if( SFX_ITEM_SET == pArgs->GetItemState(
220 0 : FN_PARAM_FIELD_CONTENT, sal_False, &pItem ))
221 0 : aPar2 = ((SfxStringItem *)pItem)->GetValue();
222 0 : if( SFX_ITEM_SET == pArgs->GetItemState(
223 0 : FN_PARAM_FIELD_FORMAT, sal_False, &pItem ))
224 0 : nFormat = ((SfxUInt32Item *)pItem)->GetValue();
225 : OSL_FAIL("Command is not yet used");
226 0 : sal_Unicode cSeparator = ' ';
227 0 : SwInsertFld_Data aData(nType, 0, aPar1, aPar2, nFormat, GetShellPtr(), cSeparator );
228 0 : bRes = aFldMgr.InsertFld(aData);
229 : }
230 0 : rReq.SetReturnValue(SfxBoolItem( nSlot, bRes ));
231 : }
232 0 : break;
233 : case FN_INSERT_FIELD_CTRL:
234 : case FN_INSERT_FIELD:
235 : {
236 0 : sal_Bool bRes = sal_False;
237 0 : if( pItem && nSlot != FN_INSERT_FIELD_CTRL)
238 : {
239 0 : sal_uLong nFormat = 0;
240 0 : sal_uInt16 nType = 0;
241 0 : sal_uInt16 nSubType = 0;
242 0 : String aPar1 = ((SfxStringItem *)pItem)->GetValue();
243 0 : String aPar2;
244 0 : sal_Unicode cSeparator = ' ';
245 :
246 0 : if( SFX_ITEM_SET == pArgs->GetItemState( FN_PARAM_FIELD_TYPE,
247 0 : sal_False, &pItem ))
248 0 : nType = ((SfxUInt16Item *)pItem)->GetValue();
249 0 : if( SFX_ITEM_SET == pArgs->GetItemState( FN_PARAM_FIELD_SUBTYPE,
250 0 : sal_False, &pItem ))
251 0 : nSubType = ((SfxUInt16Item *)pItem)->GetValue();
252 0 : if( SFX_ITEM_SET == pArgs->GetItemState(
253 0 : FN_PARAM_FIELD_CONTENT, sal_False, &pItem ))
254 0 : aPar2 = ((SfxStringItem *)pItem)->GetValue();
255 0 : if( SFX_ITEM_SET == pArgs->GetItemState(
256 0 : FN_PARAM_FIELD_FORMAT, sal_False, &pItem ))
257 0 : nFormat = ((SfxUInt32Item *)pItem)->GetValue();
258 0 : if( SFX_ITEM_SET == pArgs->GetItemState(
259 0 : FN_PARAM_3, sal_False, &pItem ))
260 : {
261 0 : String sTmp = ((SfxStringItem *)pItem)->GetValue();
262 0 : if(sTmp.Len())
263 0 : cSeparator = sTmp.GetChar(0);
264 : }
265 0 : SwInsertFld_Data aData(nType, nSubType, aPar1, aPar2, nFormat, GetShellPtr(), cSeparator );
266 0 : bRes = aFldMgr.InsertFld( aData );
267 : }
268 : else
269 : //#i5788# prevent closing of the field dialog while a modal dialog ( Input field dialog ) is active
270 0 : if(!GetView().GetViewFrame()->IsInModalMode())
271 : {
272 0 : SfxViewFrame* pVFrame = GetView().GetViewFrame();
273 0 : pVFrame->ToggleChildWindow(FN_INSERT_FIELD);
274 0 : bRes = pVFrame->GetChildWindow( nSlot ) != 0;
275 0 : Invalidate(rReq.GetSlot());
276 0 : Invalidate(FN_INSERT_FIELD_CTRL);
277 0 : rReq.Ignore();
278 : }
279 0 : rReq.SetReturnValue(SfxBoolItem( nSlot, bRes ));
280 : }
281 0 : break;
282 :
283 : case FN_INSERT_REF_FIELD:
284 : {
285 0 : SfxViewFrame* pVFrame = GetView().GetViewFrame();
286 0 : if (!pVFrame->HasChildWindow(FN_INSERT_FIELD))
287 0 : pVFrame->ToggleChildWindow(FN_INSERT_FIELD); // Show dialog
288 :
289 : // Switch Flddlg at a new TabPage
290 0 : sal_uInt16 nId = SwFldDlgWrapper::GetChildWindowId();
291 0 : SwFldDlgWrapper *pWrp = (SwFldDlgWrapper*)pVFrame->GetChildWindow(nId);
292 0 : if (pWrp)
293 0 : pWrp->ShowPage();
294 0 : rReq.Ignore();
295 : }
296 0 : break;
297 : case FN_DELETE_COMMENT:
298 0 : if ( GetView().GetPostItMgr() &&
299 0 : GetView().GetPostItMgr()->HasActiveSidebarWin() )
300 : {
301 0 : GetView().GetPostItMgr()->DeleteActiveSidebarWin();
302 : }
303 0 : break;
304 : case FN_DELETE_ALL_NOTES:
305 0 : if ( GetView().GetPostItMgr() )
306 0 : GetView().GetPostItMgr()->Delete();
307 0 : break;
308 : case FN_DELETE_NOTE_AUTHOR:
309 : {
310 0 : SFX_REQUEST_ARG( rReq, pNoteItem, SfxStringItem, nSlot, sal_False);
311 0 : if ( pNoteItem && GetView().GetPostItMgr() )
312 0 : GetView().GetPostItMgr()->Delete( pNoteItem->GetValue() );
313 : }
314 0 : break;
315 : case FN_HIDE_NOTE:
316 0 : if ( GetView().GetPostItMgr() &&
317 0 : GetView().GetPostItMgr()->HasActiveSidebarWin() )
318 : {
319 0 : GetView().GetPostItMgr()->HideActiveSidebarWin();
320 : }
321 0 : break;
322 : case FN_HIDE_ALL_NOTES:
323 0 : if ( GetView().GetPostItMgr() )
324 0 : GetView().GetPostItMgr()->Hide();
325 0 : break;
326 : case FN_HIDE_NOTE_AUTHOR:
327 : {
328 0 : SFX_REQUEST_ARG( rReq, pNoteItem, SfxStringItem, nSlot, sal_False);
329 0 : if ( pNoteItem && GetView().GetPostItMgr() )
330 0 : GetView().GetPostItMgr()->Hide( pNoteItem->GetValue() );
331 : }
332 0 : break;
333 : case FN_POSTIT:
334 : {
335 0 : SwPostItField* pPostIt = (SwPostItField*)aFldMgr.GetCurFld();
336 0 : bool bNew = !(pPostIt && pPostIt->GetTyp()->Which() == RES_POSTITFLD);
337 0 : if (bNew || GetView().GetPostItMgr()->IsAnswer())
338 : {
339 0 : SvtUserOptions aUserOpt;
340 0 : String sAuthor;
341 0 : if( !(sAuthor = aUserOpt.GetFullName()).Len())
342 0 : if( !(sAuthor = aUserOpt.GetID()).Len() )
343 0 : sAuthor = String( SW_RES( STR_REDLINE_UNKNOWN_AUTHOR ));
344 :
345 : // Save the current selection, it will be required later for fieldmark insertion.
346 0 : SwPaM& rCurrPam = rSh.GetCurrentShellCursor();
347 0 : SwPaM aSaved(*rCurrPam.GetPoint(), *rCurrPam.GetMark());
348 0 : if( rSh.HasSelection() )
349 : {
350 0 : rSh.NormalizePam(false);
351 0 : rSh.KillPams();
352 0 : rSh.ClearMark();
353 : }
354 :
355 : // #i120513# Inserting a comment into an autocompletion crashes
356 : // --> suggestion has to be removed before
357 0 : GetView().GetEditWin().StopQuickHelp();
358 :
359 0 : SwInsertFld_Data aData(TYP_POSTITFLD, 0, sAuthor, aEmptyStr, 0);
360 0 : aFldMgr.InsertFld(aData, &aSaved);
361 :
362 0 : rSh.Push();
363 0 : rSh.SwCrsrShell::Left(1, CRSR_SKIP_CHARS, sal_False);
364 0 : pPostIt = (SwPostItField*)aFldMgr.GetCurFld();
365 0 : rSh.Pop(sal_False); // Restore cursor position
366 : }
367 :
368 0 : if (pPostIt)
369 : {
370 0 : SwFieldType* pType = rSh.GetDoc()->GetFldType(RES_POSTITFLD, aEmptyStr,false);
371 0 : SwIterator<SwFmtFld,SwFieldType> aIter( *pType );
372 0 : SwFmtFld* pSwFmtFld = aIter.First();
373 0 : while( pSwFmtFld )
374 : {
375 0 : if ( pSwFmtFld->GetFld() == pPostIt )
376 : {
377 0 : pSwFmtFld->Broadcast( SwFmtFldHint( 0, SWFMTFLD_FOCUS, &GetView() ) );
378 0 : break;
379 : }
380 0 : pSwFmtFld = aIter.Next();
381 0 : }
382 : }
383 : }
384 0 : break;
385 : case FN_REDLINE_COMMENT:
386 : {
387 : /* this code can be used once we want redline comments in the margin, all other stuff can
388 : then be deleted
389 : String sComment;
390 : const SwRedline *pRedline = rSh.GetCurrRedline();
391 :
392 : if (pRedline)
393 : {
394 : sComment = pRedline->GetComment();
395 : if ( !sComment.Len() )
396 : GetView().GetDocShell()->Broadcast(SwRedlineHint(pRedline,SWREDLINE_INSERTED));
397 : const_cast<SwRedline*>(pRedline)->Broadcast(SwRedlineHint(pRedline,SWREDLINE_FOCUS,&GetView()));
398 : }
399 : */
400 :
401 0 : const SwRedline *pRedline = rSh.GetCurrRedline();
402 :
403 0 : if (pRedline)
404 : {
405 0 : OUString sComment = convertLineEnd(pRedline->GetComment(), GetSystemLineEnd());
406 :
407 0 : sal_Bool bTravel = sal_False;
408 :
409 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
410 : OSL_ENSURE(pFact, "Dialogdiet fail!");
411 0 : ::DialogGetRanges fnGetRange = pFact->GetDialogGetRangesFunc();
412 : OSL_ENSURE(fnGetRange, "Dialogdiet fail! GetRanges()");
413 0 : SfxItemSet aSet(GetPool(), fnGetRange());
414 0 : aSet.Put(SvxPostItTextItem(sComment, SID_ATTR_POSTIT_TEXT));
415 0 : aSet.Put(SvxPostItAuthorItem(pRedline->GetAuthorString(), SID_ATTR_POSTIT_AUTHOR));
416 :
417 : aSet.Put( SvxPostItDateItem( GetAppLangDateTimeString(
418 0 : pRedline->GetRedlineData().GetTimeStamp() ),
419 0 : SID_ATTR_POSTIT_DATE ));
420 :
421 : // Traveling only if more than one field.
422 0 : rSh.StartAction();
423 :
424 0 : rSh.Push();
425 0 : const SwRedline *pActRed = rSh.SelPrevRedline();
426 :
427 0 : if (pActRed == pRedline)
428 : { // New cursor is at the beginning of the current redlines.
429 0 : rSh.Pop(); // Throw old cursor away
430 0 : rSh.Push();
431 0 : pActRed = rSh.SelPrevRedline();
432 : }
433 :
434 0 : sal_Bool bPrev = pActRed != 0;
435 0 : rSh.Pop(sal_False);
436 0 : rSh.EndAction();
437 :
438 0 : rSh.ClearMark();
439 0 : rSh.SelNextRedline(); // Select current redline.
440 :
441 0 : rSh.StartAction();
442 0 : rSh.Push();
443 0 : pActRed = rSh.SelNextRedline();
444 0 : sal_Bool bNext = pActRed != 0;
445 0 : rSh.Pop(sal_False); // Restore cursor position
446 :
447 0 : if( rSh.IsCrsrPtAtEnd() )
448 0 : rSh.SwapPam();
449 :
450 0 : rSh.EndAction();
451 :
452 0 : bTravel |= bNext|bPrev;
453 :
454 0 : SvxAbstractDialogFactory* pFact2 = SvxAbstractDialogFactory::Create();
455 : OSL_ENSURE(pFact2, "Dialogdiet fail!");
456 0 : AbstractSvxPostItDialog* pDlg = pFact2->CreateSvxPostItDialog( pMDI, aSet, bTravel );
457 : OSL_ENSURE(pDlg, "Dialogdiet fail!");
458 0 : pDlg->HideAuthor();
459 :
460 0 : String sTitle(SW_RES(STR_REDLINE_COMMENT));
461 0 : ::lcl_AppendRedlineStr( sTitle, pRedline->GetType() );
462 :
463 0 : pDlg->SetText(sTitle);
464 :
465 0 : if (bTravel)
466 : {
467 0 : pDlg->EnableTravel(bNext, bPrev);
468 0 : pDlg->SetPrevHdl(LINK(this, SwTextShell, RedlinePrevHdl));
469 0 : pDlg->SetNextHdl(LINK(this, SwTextShell, RedlineNextHdl));
470 : }
471 :
472 0 : rSh.SetCareWin(pDlg->GetWindow());
473 0 : bNoInterrupt = true;
474 :
475 0 : if ( pDlg->Execute() == RET_OK )
476 : {
477 0 : const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
478 0 : String sMsg(((const SvxPostItTextItem&)pOutSet->Get(SID_ATTR_POSTIT_TEXT)).GetValue());
479 :
480 : // Insert or change a comment
481 0 : rSh.SetRedlineComment(sMsg);
482 : }
483 :
484 0 : delete pDlg;
485 0 : rSh.SetCareWin(NULL);
486 0 : bNoInterrupt = false;
487 0 : rSh.ClearMark();
488 0 : GetView().AttrChangedNotify(GetShellPtr());
489 : }
490 : }
491 0 : break;
492 :
493 : case FN_JAVAEDIT:
494 : {
495 0 : OUString aType, aText;
496 0 : sal_Bool bIsUrl=sal_False;
497 0 : sal_Bool bNew=sal_False;
498 0 : bool bUpdate = false;
499 0 : SwFldMgr* pMgr = new SwFldMgr;
500 0 : if ( pItem )
501 : {
502 0 : aText = ((SfxStringItem*)pItem)->GetValue();
503 0 : SFX_REQUEST_ARG( rReq, pType, SfxStringItem, FN_PARAM_2 , sal_False );
504 0 : SFX_REQUEST_ARG( rReq, pIsUrl, SfxBoolItem, FN_PARAM_1 , sal_False );
505 0 : if ( pType )
506 0 : aType = pType->GetValue();
507 0 : if ( pIsUrl )
508 0 : bIsUrl = pIsUrl->GetValue();
509 :
510 0 : SwScriptField* pFld = (SwScriptField*)pMgr->GetCurFld();
511 0 : bNew = !pFld || !(pFld->GetTyp()->Which() == RES_SCRIPTFLD);
512 0 : bUpdate = pFld && ( bIsUrl != pFld->GetFormat() || pFld->GetPar2() != aType || pFld->GetPar1() != aText );
513 : }
514 : else
515 : {
516 0 : SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
517 : OSL_ENSURE(pFact, "Dialogdiet fail!");
518 0 : AbstractJavaEditDialog* pDlg = pFact->CreateJavaEditDialog(pMDI, &rSh);
519 : OSL_ENSURE(pDlg, "Dialogdiet fail!");
520 0 : if ( pDlg->Execute() )
521 : {
522 0 : aType = pDlg->GetType();
523 0 : aText = pDlg->GetText();
524 0 : bIsUrl = pDlg->IsUrl();
525 0 : bNew = pDlg->IsNew();
526 0 : bUpdate = pDlg->IsUpdate();
527 0 : rReq.AppendItem( SfxStringItem( FN_JAVAEDIT, aText ) );
528 0 : rReq.AppendItem( SfxStringItem( FN_PARAM_2, aType ) );
529 0 : rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bIsUrl ) );
530 : }
531 :
532 0 : delete pDlg;
533 : }
534 :
535 0 : if( bNew )
536 : {
537 0 : SwInsertFld_Data aData(TYP_SCRIPTFLD, 0, aType, aText, bIsUrl);
538 0 : pMgr->InsertFld(aData);
539 0 : rReq.Done();
540 : }
541 0 : else if( bUpdate )
542 : {
543 0 : pMgr->UpdateCurFld( bIsUrl, aType, aText );
544 0 : rSh.SetUndoNoResetModified();
545 0 : rReq.Done();
546 : }
547 : else
548 0 : rReq.Ignore();
549 : }
550 0 : break;
551 :
552 : case FN_INSERT_FLD_DATE :
553 0 : nInsertType = TYP_DATEFLD;
554 0 : bIsText = false;
555 0 : goto FIELD_INSERT;
556 : case FN_INSERT_FLD_TIME :
557 0 : nInsertType = TYP_TIMEFLD;
558 0 : bIsText = false;
559 0 : goto FIELD_INSERT;
560 : case FN_INSERT_FLD_PGNUMBER:
561 0 : nInsertType = TYP_PAGENUMBERFLD;
562 0 : nInsertFormat = SVX_NUM_PAGEDESC; // Like page template
563 0 : bIsText = false;
564 0 : goto FIELD_INSERT;
565 : case FN_INSERT_FLD_PGCOUNT :
566 0 : nInsertType = TYP_DOCSTATFLD;
567 0 : nInsertSubType = 0;
568 0 : bIsText = false;
569 0 : nInsertFormat = SVX_NUM_PAGEDESC;
570 0 : goto FIELD_INSERT;
571 : case FN_INSERT_FLD_TOPIC :
572 0 : nInsertType = TYP_DOCINFOFLD;
573 0 : nInsertSubType = DI_THEMA;
574 0 : goto FIELD_INSERT;
575 : case FN_INSERT_FLD_TITLE :
576 0 : nInsertType = TYP_DOCINFOFLD;
577 0 : nInsertSubType = DI_TITEL;
578 0 : goto FIELD_INSERT;
579 : case FN_INSERT_FLD_AUTHOR :
580 0 : nInsertType = TYP_DOCINFOFLD;
581 0 : nInsertSubType = DI_CREATE|DI_SUB_AUTHOR;
582 :
583 : FIELD_INSERT:
584 : {
585 : //format conversion should only be done for number formatter formats
586 0 : if(!nInsertFormat)
587 0 : nInsertFormat = aFldMgr.GetDefaultFormat(nInsertType, bIsText, rSh.GetNumberFormatter());
588 : SwInsertFld_Data aData(nInsertType, nInsertSubType,
589 0 : aEmptyStr, aEmptyStr, nInsertFormat);
590 0 : aFldMgr.InsertFld(aData);
591 0 : rReq.Done();
592 : }
593 0 : break;
594 : default:
595 : OSL_FAIL("wrong dispatcher");
596 0 : return;
597 0 : }
598 : }
599 : }
600 :
601 7 : void SwTextShell::StateField( SfxItemSet &rSet )
602 : {
603 7 : SwWrtShell& rSh = GetShell();
604 7 : SfxWhichIter aIter( rSet );
605 7 : const SwField* pField = 0;
606 7 : int bGetField = sal_False;
607 7 : sal_uInt16 nWhich = aIter.FirstWhich();
608 :
609 21 : while (nWhich)
610 : {
611 7 : switch (nWhich)
612 : {
613 : case FN_DELETE_COMMENT:
614 : case FN_DELETE_NOTE_AUTHOR:
615 : case FN_DELETE_ALL_NOTES:
616 : case FN_HIDE_NOTE:
617 : case FN_HIDE_NOTE_AUTHOR:
618 : case FN_HIDE_ALL_NOTES:
619 : {
620 0 : SwPostItMgr* pPostItMgr = GetView().GetPostItMgr();
621 0 : if ( !pPostItMgr )
622 0 : rSet.InvalidateItem( nWhich );
623 0 : else if ( !pPostItMgr->HasActiveSidebarWin() )
624 : {
625 0 : rSet.InvalidateItem( FN_DELETE_COMMENT );
626 0 : rSet.InvalidateItem( FN_HIDE_NOTE );
627 : }
628 : }
629 0 : break;
630 : case FN_EDIT_FIELD:
631 : {
632 :
633 7 : if( !bGetField )
634 : {
635 7 : pField = rSh.GetCurFld();
636 7 : bGetField = sal_True;
637 : }
638 :
639 7 : sal_uInt16 nTempWhich = pField ? pField->GetTyp()->Which() : USHRT_MAX;
640 7 : if( USHRT_MAX == nTempWhich ||
641 0 : RES_POSTITFLD == nTempWhich ||
642 0 : RES_SCRIPTFLD == nTempWhich ||
643 : RES_AUTHORITY == nTempWhich )
644 7 : rSet.DisableItem( nWhich );
645 0 : else if( RES_DDEFLD == nTempWhich &&
646 0 : !((SwDDEFieldType*)pField->GetTyp())->GetBaseLink().IsVisible())
647 : {
648 : // nested links cannot be edited
649 0 : rSet.DisableItem( nWhich );
650 : }
651 : }
652 7 : break;
653 : case FN_EXECUTE_MACROFIELD:
654 : {
655 0 : if(!bGetField)
656 : {
657 0 : pField = rSh.GetCurFld();
658 0 : bGetField = sal_True;
659 : }
660 0 : if(!pField || pField->GetTyp()->Which() != RES_MACROFLD)
661 0 : rSet.DisableItem(nWhich);
662 : }
663 0 : break;
664 :
665 : case FN_INSERT_FIELD:
666 : {
667 0 : SfxViewFrame* pVFrame = GetView().GetViewFrame();
668 : //#i5788# prevent closing of the field dialog while a modal dialog ( Input field dialog ) is active
669 0 : if(!pVFrame->IsInModalMode() &&
670 0 : pVFrame->KnowsChildWindow(FN_INSERT_FIELD) && !pVFrame->HasChildWindow(FN_INSERT_FIELD_DATA_ONLY) )
671 0 : rSet.Put(SfxBoolItem( FN_INSERT_FIELD, pVFrame->HasChildWindow(nWhich)));
672 : else
673 0 : rSet.DisableItem(FN_INSERT_FIELD);
674 : }
675 0 : break;
676 : case FN_INSERT_REF_FIELD:
677 : {
678 0 : SfxViewFrame* pVFrame = GetView().GetViewFrame();
679 0 : if (!pVFrame->KnowsChildWindow(FN_INSERT_FIELD))
680 0 : rSet.DisableItem(FN_INSERT_REF_FIELD);
681 : }
682 0 : break;
683 : case FN_INSERT_FIELD_CTRL:
684 0 : rSet.Put(SfxBoolItem( nWhich, GetView().GetViewFrame()->HasChildWindow(FN_INSERT_FIELD)));
685 0 : break;
686 : case FN_REDLINE_COMMENT:
687 0 : if (!rSh.GetCurrRedline())
688 0 : rSet.DisableItem(nWhich);
689 0 : break;
690 : case FN_POSTIT :
691 : case FN_JAVAEDIT :
692 0 : bool bCurField = false;
693 0 : pField = rSh.GetCurFld();
694 0 : if(nWhich == FN_POSTIT)
695 0 : bCurField = pField && pField->GetTyp()->Which() == RES_POSTITFLD;
696 : else
697 0 : bCurField = pField && pField->GetTyp()->Which() == RES_SCRIPTFLD;
698 :
699 0 : if(!bCurField && rSh.IsReadOnlyAvailable() && rSh.HasReadonlySel() )
700 0 : rSet.DisableItem(nWhich);
701 0 : break;
702 : }
703 7 : nWhich = aIter.NextWhich();
704 7 : }
705 7 : }
706 :
707 0 : void SwTextShell::InsertHyperlink(const SvxHyperlinkItem& rHlnkItem)
708 : {
709 0 : const String& rName = rHlnkItem.GetName();
710 0 : const String& rURL = rHlnkItem.GetURL();
711 0 : const String& rTarget = rHlnkItem.GetTargetFrame();
712 0 : sal_uInt16 nType = (sal_uInt16)rHlnkItem.GetInsertMode();
713 0 : nType &= ~HLINK_HTMLMODE;
714 0 : const SvxMacroTableDtor* pMacroTbl = rHlnkItem.GetMacroTbl();
715 :
716 0 : SwWrtShell& rSh = GetShell();
717 :
718 0 : if( rSh.GetSelectionType() & nsSelectionType::SEL_TXT )
719 : {
720 0 : rSh.StartAction();
721 0 : SfxItemSet aSet(GetPool(), RES_TXTATR_INETFMT, RES_TXTATR_INETFMT);
722 0 : rSh.GetCurAttr( aSet );
723 :
724 : const SfxPoolItem* pItem;
725 0 : if(SFX_ITEM_SET == aSet.GetItemState(RES_TXTATR_INETFMT, sal_False, &pItem))
726 : {
727 : // Select links
728 0 : rSh.SwCrsrShell::SelectTxtAttr(RES_TXTATR_INETFMT, sal_False);
729 : }
730 0 : switch (nType)
731 : {
732 : case HLINK_DEFAULT:
733 : case HLINK_FIELD:
734 : {
735 0 : SwFmtINetFmt aINetFmt( rURL, rTarget );
736 0 : aINetFmt.SetName(rHlnkItem.GetIntName());
737 0 : if(pMacroTbl)
738 : {
739 0 : const SvxMacro *pMacro = pMacroTbl->Get( SFX_EVENT_MOUSEOVER_OBJECT );
740 0 : if( pMacro )
741 0 : aINetFmt.SetMacro(SFX_EVENT_MOUSEOVER_OBJECT, *pMacro);
742 0 : pMacro = pMacroTbl->Get( SFX_EVENT_MOUSECLICK_OBJECT );
743 0 : if( pMacro )
744 0 : aINetFmt.SetMacro(SFX_EVENT_MOUSECLICK_OBJECT, *pMacro);
745 0 : pMacro = pMacroTbl->Get( SFX_EVENT_MOUSEOUT_OBJECT );
746 0 : if( pMacro )
747 0 : aINetFmt.SetMacro(SFX_EVENT_MOUSEOUT_OBJECT, *pMacro);
748 : }
749 0 : rSh.SttSelect();
750 0 : rSh.InsertURL( aINetFmt, rName, sal_True );
751 0 : rSh.EndSelect();
752 : }
753 0 : break;
754 :
755 : case HLINK_BUTTON:
756 0 : sal_Bool bSel = rSh.HasSelection();
757 0 : if(bSel)
758 0 : rSh.DelRight();
759 0 : InsertURLButton( rURL, rTarget, rName );
760 0 : rSh.EnterStdMode();
761 0 : break;
762 : }
763 0 : rSh.EndAction();
764 : }
765 0 : }
766 :
767 0 : IMPL_LINK( SwTextShell, RedlineNextHdl, AbstractSvxPostItDialog *, pBtn )
768 : {
769 0 : SwWrtShell* pSh = GetShellPtr();
770 0 : AbstractSvxPostItDialog *pDlg = (AbstractSvxPostItDialog*)pBtn;
771 :
772 : // Insert or change a comment.
773 0 : pSh->SetRedlineComment(pDlg->GetNote());
774 :
775 0 : const SwRedline *pRedline = pSh->GetCurrRedline();
776 :
777 0 : if (pRedline)
778 : {
779 : // Traveling only if more than one field.
780 0 : if( !pSh->IsCrsrPtAtEnd() )
781 0 : pSh->SwapPam(); // Move the cursor behind the Redline.
782 :
783 0 : pSh->Push();
784 0 : const SwRedline *pActRed = pSh->SelNextRedline();
785 0 : pSh->Pop(pActRed != 0);
786 :
787 0 : sal_Bool bEnable = sal_False;
788 :
789 0 : if (pActRed)
790 : {
791 0 : pSh->StartAction();
792 0 : pSh->Push();
793 0 : bEnable = pSh->SelNextRedline() != 0;
794 0 : pSh->Pop(sal_False);
795 0 : pSh->EndAction();
796 : }
797 :
798 0 : pDlg->EnableTravel(bEnable, sal_True);
799 :
800 0 : if( pSh->IsCrsrPtAtEnd() )
801 0 : pSh->SwapPam();
802 :
803 0 : pRedline = pSh->GetCurrRedline();
804 0 : OUString sComment = convertLineEnd(pRedline->GetComment(), GetSystemLineEnd());
805 :
806 0 : pDlg->SetNote(sComment);
807 0 : pDlg->ShowLastAuthor( pRedline->GetAuthorString(),
808 : GetAppLangDateTimeString(
809 0 : pRedline->GetRedlineData().GetTimeStamp() ));
810 :
811 0 : String sTitle(SW_RES(STR_REDLINE_COMMENT));
812 0 : ::lcl_AppendRedlineStr( sTitle, pRedline->GetType() );
813 :
814 0 : pDlg->SetText(sTitle);
815 : }
816 :
817 0 : return 0;
818 : }
819 :
820 0 : IMPL_LINK( SwTextShell, RedlinePrevHdl, AbstractSvxPostItDialog *, pBtn )
821 : {
822 0 : SwWrtShell* pSh = GetShellPtr();
823 0 : AbstractSvxPostItDialog *pDlg = (AbstractSvxPostItDialog*)pBtn;
824 :
825 : // Insert or change a comment.
826 0 : pSh->SetRedlineComment(pDlg->GetNote());
827 :
828 0 : const SwRedline *pRedline = pSh->GetCurrRedline();
829 :
830 0 : if (pRedline)
831 : {
832 : // Traveling only if more than one field.
833 0 : pSh->Push();
834 0 : const SwRedline *pActRed = pSh->SelPrevRedline();
835 0 : pSh->Pop(pActRed != 0);
836 :
837 0 : sal_Bool bEnable = sal_False;
838 :
839 0 : if (pActRed)
840 : {
841 0 : pSh->StartAction();
842 0 : pSh->Push();
843 0 : bEnable = pSh->SelPrevRedline() != 0;
844 0 : pSh->Pop(sal_False);
845 0 : pSh->EndAction();
846 : }
847 :
848 0 : pDlg->EnableTravel(sal_True, bEnable);
849 :
850 0 : pRedline = pSh->GetCurrRedline();
851 0 : OUString sComment = convertLineEnd(pRedline->GetComment(), GetSystemLineEnd());
852 :
853 0 : pDlg->SetNote(sComment);
854 0 : pDlg->ShowLastAuthor(pRedline->GetAuthorString(),
855 : GetAppLangDateTimeString(
856 0 : pRedline->GetRedlineData().GetTimeStamp() ));
857 :
858 0 : String sTitle(SW_RES(STR_REDLINE_COMMENT));
859 0 : ::lcl_AppendRedlineStr( sTitle, pRedline->GetType() );
860 :
861 0 : pDlg->SetText(sTitle);
862 : }
863 :
864 0 : return 0;
865 99 : }
866 :
867 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|