cid#1607171 Data race condition
[LibreOffice.git] / sd / source / ui / view / outlnvs2.cxx
blob99935ec3ec571021c91a0d8cf4fbf90081b80d2d
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 .
20 #include <OutlineViewShell.hxx>
21 #include <Outliner.hxx>
23 #include <app.hrc>
24 #include <svx/hlnkitem.hxx>
25 #include <sfx2/bindings.hxx>
26 #include <sfx2/docfile.hxx>
27 #include <sfx2/request.hxx>
28 #include <sfx2/zoomitem.hxx>
29 #include <svx/svxids.hrc>
30 #include <svx/svdoutl.hxx>
31 #include <svx/zoomslideritem.hxx>
32 #include <editeng/eeitem.hxx>
33 #include <editeng/flditem.hxx>
34 #include <editeng/editstat.hxx>
35 #include <unotools/useroptions.hxx>
37 #include <sfx2/viewfrm.hxx>
38 #include <Window.hxx>
39 #include <fubullet.hxx>
40 #include <fuolbull.hxx>
41 #include <fuscale.hxx>
42 #include <fuchar.hxx>
43 #include <fuinsfil.hxx>
44 #include <fuprobjs.hxx>
45 #include <futhes.hxx>
46 #include <futempl.hxx>
47 #include <fusldlg.hxx>
48 #include <zoomlist.hxx>
49 #include <fuexpand.hxx>
50 #include <fusumry.hxx>
51 #include <fucushow.hxx>
52 #include <sdabstdlg.hxx>
53 #include <DrawDocShell.hxx>
54 #include <DrawViewShell.hxx>
55 #include <OutlineView.hxx>
56 #include <slideshow.hxx>
57 #include <memory>
59 namespace sd {
61 /************************************************************************/
63 /**
64 * SfxRequests for temporary functions
67 void OutlineViewShell::FuTemporary(SfxRequest &rReq)
69 DeactivateCurrentFunction();
71 OutlinerView* pOutlinerView = pOlView->GetViewByWindow( GetActiveWindow() );
72 sal_uInt16 nSId = rReq.GetSlot();
74 switch( nSId )
76 case SID_ATTR_ZOOM:
78 const SfxItemSet* pArgs = rReq.GetArgs();
80 if ( pArgs )
82 SvxZoomType eZT = pArgs->Get( SID_ATTR_ZOOM ).GetType();
83 switch( eZT )
85 case SvxZoomType::PERCENT:
86 SetZoom( static_cast<::tools::Long>( pArgs->Get( SID_ATTR_ZOOM ).GetValue()) );
87 Invalidate( SID_ATTR_ZOOM );
88 Invalidate( SID_ATTR_ZOOMSLIDER );
89 break;
90 default:
91 break;
93 rReq.Done();
95 else
97 // open the zoom dialog here
98 SetCurrentFunction( FuScale::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
100 Cancel();
102 break;
104 case SID_ATTR_ZOOMSLIDER:
106 const SfxItemSet* pArgs = rReq.GetArgs();
108 const SfxUInt16Item* pScale = (pArgs && pArgs->Count () == 1) ?
109 rReq.GetArg(SID_ATTR_ZOOMSLIDER) : nullptr;
110 if (pScale && CHECK_RANGE (5, pScale->GetValue (), 3000))
112 SetZoom (pScale->GetValue ());
114 SfxBindings& rBindings = GetViewFrame()->GetBindings();
115 rBindings.Invalidate( SID_ATTR_ZOOM );
116 rBindings.Invalidate( SID_ZOOM_IN );
117 rBindings.Invalidate( SID_ZOOM_OUT );
118 rBindings.Invalidate( SID_ATTR_ZOOMSLIDER );
122 Cancel();
123 rReq.Done ();
124 break;
127 case SID_ZOOM_IN:
129 SetZoom( std::min<::tools::Long>( GetActiveWindow()->GetZoom() * 2, GetActiveWindow()->GetMaxZoom() ) );
130 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0),
131 GetActiveWindow()->GetOutputSizePixel()) );
132 mpZoomList->InsertZoomRect(aVisAreaWin);
133 Invalidate( SID_ATTR_ZOOM );
134 Invalidate( SID_ZOOM_IN );
135 Invalidate(SID_ZOOM_OUT);
136 Invalidate( SID_ATTR_ZOOMSLIDER );
137 Cancel();
138 rReq.Done();
140 break;
142 case SID_SIZE_REAL:
144 SetZoom( 100 );
145 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0),
146 GetActiveWindow()->GetOutputSizePixel()) );
147 mpZoomList->InsertZoomRect(aVisAreaWin);
148 Invalidate( SID_ATTR_ZOOM );
149 Invalidate( SID_ATTR_ZOOMSLIDER );
150 Cancel();
151 rReq.Done();
153 break;
155 case SID_ZOOM_OUT:
157 SetZoom( std::max<::tools::Long>( GetActiveWindow()->GetZoom() / 2, GetActiveWindow()->GetMinZoom() ) );
158 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0),
159 GetActiveWindow()->GetOutputSizePixel()) );
160 mpZoomList->InsertZoomRect(aVisAreaWin);
161 Invalidate( SID_ATTR_ZOOM );
162 Invalidate( SID_ZOOM_OUT);
163 Invalidate( SID_ZOOM_IN );
164 Invalidate( SID_ATTR_ZOOMSLIDER );
165 Cancel();
166 rReq.Done();
168 break;
170 case SID_OUTLINE_COLLAPSE_ALL:
172 pOutlinerView->CollapseAll();
173 Cancel();
174 rReq.Done();
176 break;
178 case SID_OUTLINE_COLLAPSE:
180 pOutlinerView->Collapse();
181 Cancel();
182 rReq.Done();
184 break;
186 case SID_OUTLINE_EXPAND_ALL:
188 pOutlinerView->ExpandAll();
189 Cancel();
190 rReq.Done();
192 break;
194 case SID_OUTLINE_EXPAND:
196 pOutlinerView->Expand();
197 Cancel();
198 rReq.Done();
200 break;
202 case SID_OUTLINE_FORMAT:
204 ::Outliner* pOutl = pOutlinerView->GetOutliner();
205 pOutl->SetFlatMode( !pOutl->IsFlatMode() );
206 Invalidate( SID_COLORVIEW );
207 Cancel();
208 rReq.Done();
210 break;
212 case SID_SELECTALL:
214 ::Outliner& rOutl = pOlView->GetOutliner();
215 sal_Int32 nParaCount = rOutl.GetParagraphCount();
216 if (nParaCount > 0)
218 pOutlinerView->SelectRange( 0, nParaCount );
220 Cancel();
222 break;
224 case SID_PRESENTATION:
225 case SID_PRESENTATION_CURRENT_SLIDE:
226 case SID_REHEARSE_TIMINGS:
228 pOlView->PrepareClose();
229 slideshowhelp::ShowSlideShow(rReq, *GetDoc());
230 Cancel();
231 rReq.Done();
233 break;
235 case SID_COLORVIEW:
237 ::Outliner* pOutl = pOutlinerView->GetOutliner();
238 EEControlBits nCntrl = pOutl->GetControlWord();
240 if ( !(nCntrl & EEControlBits::NOCOLORS) )
242 // color view is enabled: disable
243 pOutl->SetControlWord(nCntrl | EEControlBits::NOCOLORS);
245 else
247 // color view is disabled: enable
248 pOutl->SetControlWord(nCntrl & ~EEControlBits::NOCOLORS);
251 InvalidateWindows();
252 Invalidate( SID_COLORVIEW );
253 Cancel();
254 rReq.Done();
256 break;
258 case SID_STYLE_EDIT:
259 case SID_STYLE_UPDATE_BY_EXAMPLE:
261 if( rReq.GetArgs() )
263 SetCurrentFunction( FuTemplate::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
264 Cancel();
267 rReq.Ignore ();
269 break;
271 case SID_PRESENTATION_DLG:
273 SetCurrentFunction( FuSlideShowDlg::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
274 Cancel();
276 break;
278 case SID_REMOTE_DLG:
280 #ifdef ENABLE_SDREMOTE
281 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
282 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateRemoteDialog(GetFrameWeld()));
283 pDlg->Execute();
284 #endif
286 break;
288 case SID_CUSTOMSHOW_DLG:
290 SetCurrentFunction( FuCustomShowDlg::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
291 Cancel();
293 break;
295 case SID_PHOTOALBUM:
297 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
298 vcl::Window* pWin = GetActiveWindow();
299 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSdPhotoAlbumDialog(
300 pWin ? pWin->GetFrameWeld() : nullptr,
301 GetDoc()));
303 pDlg->Execute();
305 Cancel();
306 rReq.Ignore ();
308 break;
311 if(HasCurrentFunction())
312 GetCurrentFunction()->Activate();
314 Invalidate( SID_OUTLINE_COLLAPSE_ALL );
315 Invalidate( SID_OUTLINE_COLLAPSE );
316 Invalidate( SID_OUTLINE_EXPAND_ALL );
317 Invalidate( SID_OUTLINE_EXPAND );
319 SfxBindings& rBindings = GetViewFrame()->GetBindings();
320 rBindings.Invalidate( SID_OUTLINE_LEFT );
321 rBindings.Invalidate( SID_OUTLINE_RIGHT );
322 rBindings.Invalidate( SID_OUTLINE_UP );
323 rBindings.Invalidate( SID_OUTLINE_DOWN );
325 Invalidate( SID_OUTLINE_FORMAT );
326 Invalidate( SID_COLORVIEW );
327 Invalidate(SID_CUT);
328 Invalidate(SID_COPY);
329 Invalidate(SID_PASTE);
330 Invalidate(SID_PASTE_UNFORMATTED);
333 void OutlineViewShell::FuTemporaryModify(SfxRequest &rReq)
335 sal_uInt16 nSId = rReq.GetSlot();
336 std::unique_ptr<OutlineViewModelChangeGuard, o3tl::default_delete<OutlineViewModelChangeGuard>> aGuard;
337 if (nSId != SID_OUTLINE_BULLET && nSId != FN_SVX_SET_BULLET && nSId != FN_SVX_SET_NUMBER)
339 aGuard.reset( new OutlineViewModelChangeGuard(*pOlView) );
341 DeactivateCurrentFunction();
343 OutlinerView* pOutlinerView = pOlView->GetViewByWindow( GetActiveWindow() );
344 //sal_uInt16 nSId = rReq.GetSlot();
346 switch( nSId )
348 case SID_HYPERLINK_SETLINK:
350 const SfxItemSet* pReqArgs = rReq.GetArgs();
352 if (pReqArgs)
354 const SvxHyperlinkItem* pHLItem =
355 &pReqArgs->Get(SID_HYPERLINK_SETLINK);
357 SvxFieldItem aURLItem(SvxURLField(pHLItem->GetURL(),
358 pHLItem->GetName(),
359 SvxURLFormat::Repr), EE_FEATURE_FIELD);
360 ESelection aSel( pOutlinerView->GetSelection() );
361 pOutlinerView->InsertField(aURLItem);
362 if (aSel.start.nIndex <= aSel.end.nIndex)
363 aSel.end.nIndex = aSel.start.nIndex + 1;
364 else
365 aSel.start.nIndex = aSel.end.nIndex + 1;
366 pOutlinerView->SetSelection( aSel );
369 Cancel();
370 rReq.Ignore ();
372 break;
374 case FN_INSERT_SOFT_HYPHEN:
375 case FN_INSERT_HARDHYPHEN:
376 case FN_INSERT_HARD_SPACE:
377 case FN_INSERT_NNBSP:
378 case SID_INSERT_RLM :
379 case SID_INSERT_LRM :
380 case SID_INSERT_WJ :
381 case SID_INSERT_ZWSP:
382 case SID_CHARMAP:
384 SetCurrentFunction( FuBullet::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
385 Cancel();
387 break;
389 case SID_OUTLINE_BULLET:
390 case FN_SVX_SET_BULLET:
391 case FN_SVX_SET_NUMBER:
393 SetCurrentFunction( FuBulletAndPosition::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
394 Cancel();
396 break;
398 case SID_THESAURUS:
400 SetCurrentFunction( FuThesaurus::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
401 Cancel();
402 rReq.Ignore ();
404 break;
406 case SID_CHAR_DLG_EFFECT:
407 case SID_CHAR_DLG:
409 SetCurrentFunction( FuChar::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
410 Cancel();
412 break;
414 case SID_INSERTFILE:
416 SetCurrentFunction( FuInsertFile::Create(this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq) );
417 Cancel();
419 break;
421 case SID_PRESENTATIONOBJECT:
423 SetCurrentFunction( FuPresentationObjects::Create(this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq) );
424 Cancel();
426 break;
428 case SID_SET_DEFAULT:
430 pOutlinerView->RemoveAttribs(true); // sal_True = also paragraph attributes
431 Cancel();
432 rReq.Done();
434 break;
436 case SID_SUMMARY_PAGE:
438 pOlView->SetSelectedPages();
439 SetCurrentFunction( FuSummaryPage::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
440 pOlView->GetOutliner().Clear();
441 pOlView->FillOutliner();
442 pOlView->GetActualPage();
443 Cancel();
445 break;
447 case SID_EXPAND_PAGE:
449 pOlView->SetSelectedPages();
450 SetCurrentFunction( FuExpandPage::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
451 pOlView->GetOutliner().Clear();
452 pOlView->FillOutliner();
453 pOlView->GetActualPage();
454 Cancel();
456 break;
458 case SID_INSERT_FLD_DATE_FIX:
459 case SID_INSERT_FLD_DATE_VAR:
460 case SID_INSERT_FLD_TIME_FIX:
461 case SID_INSERT_FLD_TIME_VAR:
462 case SID_INSERT_FLD_AUTHOR:
463 case SID_INSERT_FLD_PAGE:
464 case SID_INSERT_FLD_PAGE_TITLE:
465 case SID_INSERT_FLD_PAGES:
466 case SID_INSERT_FLD_FILE:
468 std::unique_ptr<SvxFieldItem> pFieldItem;
470 switch( nSId )
472 case SID_INSERT_FLD_DATE_FIX:
473 pFieldItem.reset(new SvxFieldItem(
474 SvxDateField( Date( Date::SYSTEM ), SvxDateType::Fix ), EE_FEATURE_FIELD ));
475 break;
477 case SID_INSERT_FLD_DATE_VAR:
478 pFieldItem.reset(new SvxFieldItem( SvxDateField(), EE_FEATURE_FIELD ));
479 break;
481 case SID_INSERT_FLD_TIME_FIX:
482 pFieldItem.reset(new SvxFieldItem(
483 SvxExtTimeField( ::tools::Time( ::tools::Time::SYSTEM ), SvxTimeType::Fix ), EE_FEATURE_FIELD ));
484 break;
486 case SID_INSERT_FLD_TIME_VAR:
487 pFieldItem.reset(new SvxFieldItem( SvxExtTimeField(), EE_FEATURE_FIELD ));
488 break;
490 case SID_INSERT_FLD_AUTHOR:
492 SvtUserOptions aUserOptions;
493 pFieldItem.reset(new SvxFieldItem(
494 SvxAuthorField(
495 aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID() )
496 , EE_FEATURE_FIELD ));
498 break;
500 case SID_INSERT_FLD_PAGE:
501 pFieldItem.reset(new SvxFieldItem( SvxPageField(), EE_FEATURE_FIELD ));
502 break;
504 case SID_INSERT_FLD_PAGE_TITLE:
505 pFieldItem.reset(new SvxFieldItem( SvxPageTitleField(), EE_FEATURE_FIELD));
506 break;
508 case SID_INSERT_FLD_PAGES:
509 pFieldItem.reset(new SvxFieldItem( SvxPagesField(), EE_FEATURE_FIELD ));
510 break;
512 case SID_INSERT_FLD_FILE:
514 OUString aName;
515 if( GetDocSh()->HasName() )
516 aName = GetDocSh()->GetMedium()->GetName();
517 //else
518 // aName = GetDocSh()->GetName();
519 pFieldItem.reset(new SvxFieldItem( SvxExtFileField( aName ), EE_FEATURE_FIELD ));
521 break;
524 const SvxFieldItem* pOldFldItem = pOutlinerView->GetFieldAtSelection();
526 if( pOldFldItem && ( nullptr != dynamic_cast< const SvxURLField *>( pOldFldItem->GetField() ) ||
527 nullptr != dynamic_cast< const SvxDateField *>( pOldFldItem->GetField() ) ||
528 nullptr != dynamic_cast< const SvxTimeField *>( pOldFldItem->GetField() ) ||
529 nullptr != dynamic_cast< const SvxExtTimeField *>( pOldFldItem->GetField() ) ||
530 nullptr != dynamic_cast< const SvxExtFileField *>( pOldFldItem->GetField() ) ||
531 nullptr != dynamic_cast< const SvxAuthorField *>( pOldFldItem->GetField() ) ||
532 nullptr != dynamic_cast< const SvxPageField *>( pOldFldItem->GetField() ) ||
533 nullptr != dynamic_cast< const SvxPagesField *>( pOldFldItem->GetField() )) )
535 // select field, so it gets deleted on Insert
536 ESelection aSel = pOutlinerView->GetSelection();
537 if (aSel.start.nIndex == aSel.end.nIndex)
538 aSel.end.nIndex++;
539 pOutlinerView->SetSelection( aSel );
542 if( pFieldItem )
543 pOutlinerView->InsertField( *pFieldItem );
545 pFieldItem.reset();
547 Cancel();
548 rReq.Ignore ();
550 break;
552 case SID_MODIFY_FIELD:
554 const SvxFieldItem* pFldItem = pOutlinerView->GetFieldAtSelection();
556 if( pFldItem && (nullptr != dynamic_cast< const SvxDateField *>( pFldItem->GetField() ) ||
557 nullptr != dynamic_cast< const SvxAuthorField *>( pFldItem->GetField() ) ||
558 nullptr != dynamic_cast< const SvxExtFileField *>( pFldItem->GetField() ) ||
559 nullptr != dynamic_cast< const SvxExtTimeField *>( pFldItem->GetField() ) ) )
561 // Dialog...
562 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
563 vcl::Window* pWin = GetActiveWindow();
564 ScopedVclPtr<AbstractSdModifyFieldDlg> pDlg(pFact->CreateSdModifyFieldDlg(pWin ? pWin->GetFrameWeld() : nullptr, pFldItem->GetField(), pOutlinerView->GetAttribs() ));
565 if( pDlg->Execute() == RET_OK )
567 std::unique_ptr<SvxFieldData> pField(pDlg->GetField());
568 if( pField )
570 SvxFieldItem aFieldItem( *pField, EE_FEATURE_FIELD );
571 //pOLV->DeleteSelected(); <-- unfortunately missing!
572 // select field, so it gets deleted on Insert
573 ESelection aSel = pOutlinerView->GetSelection();
574 bool bSel = true;
575 if (aSel.start.nIndex == aSel.end.nIndex)
577 bSel = false;
578 aSel.end.nIndex++;
580 pOutlinerView->SetSelection( aSel );
582 pOutlinerView->InsertField( aFieldItem );
584 // reset selection to original state
585 if( !bSel )
586 aSel.end.nIndex--;
587 pOutlinerView->SetSelection( aSel );
589 pField.reset();
592 SfxItemSet aSet( pDlg->GetItemSet() );
593 if( aSet.Count() )
595 pOutlinerView->SetAttribs( aSet );
597 ::Outliner* pOutliner = pOutlinerView->GetOutliner();
598 if( pOutliner )
599 pOutliner->UpdateFields();
604 Cancel();
605 rReq.Ignore ();
607 break;
610 if(HasCurrentFunction())
611 GetCurrentFunction()->Activate();
613 Invalidate( SID_OUTLINE_COLLAPSE_ALL );
614 Invalidate( SID_OUTLINE_COLLAPSE );
615 Invalidate( SID_OUTLINE_EXPAND_ALL );
616 Invalidate( SID_OUTLINE_EXPAND );
618 SfxBindings& rBindings = GetViewFrame()->GetBindings();
619 rBindings.Invalidate( SID_OUTLINE_LEFT );
620 rBindings.Invalidate( SID_OUTLINE_RIGHT );
621 rBindings.Invalidate( SID_OUTLINE_UP );
622 rBindings.Invalidate( SID_OUTLINE_DOWN );
624 Invalidate( SID_OUTLINE_FORMAT );
625 Invalidate( SID_COLORVIEW );
626 Invalidate(SID_CUT);
627 Invalidate(SID_COPY);
628 Invalidate(SID_PASTE);
629 Invalidate(SID_PASTE_UNFORMATTED);
632 } // end of namespace sd
634 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */