Bump version to 21.06.18.1
[LibreOffice.git] / sd / source / ui / view / outlnvs2.cxx
blob94e1d90e86569289c988f2361a136fc1679f56d1
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>
22 #include <app.hrc>
23 #include <svx/hlnkitem.hxx>
24 #include <sfx2/bindings.hxx>
25 #include <sfx2/docfile.hxx>
26 #include <sfx2/request.hxx>
27 #include <sfx2/zoomitem.hxx>
28 #include <svx/svxids.hrc>
29 #include <svx/svdoutl.hxx>
30 #include <editeng/eeitem.hxx>
31 #include <editeng/flditem.hxx>
32 #include <editeng/editstat.hxx>
33 #include <unotools/useroptions.hxx>
35 #include <sfx2/viewfrm.hxx>
36 #include <Window.hxx>
37 #include <fubullet.hxx>
38 #include <fuolbull.hxx>
39 #include <fuscale.hxx>
40 #include <fuchar.hxx>
41 #include <fuinsfil.hxx>
42 #include <fuprobjs.hxx>
43 #include <futhes.hxx>
44 #include <futempl.hxx>
45 #include <fusldlg.hxx>
46 #include <zoomlist.hxx>
47 #include <fuexpand.hxx>
48 #include <fusumry.hxx>
49 #include <fucushow.hxx>
50 #include <sdabstdlg.hxx>
51 #include <DrawDocShell.hxx>
52 #include <DrawViewShell.hxx>
53 #include <OutlineView.hxx>
54 #include <slideshow.hxx>
55 #include <memory>
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::beans;
60 namespace sd {
62 /************************************************************************/
64 /**
65 * SfxRequests for temporary functions
68 void OutlineViewShell::FuTemporary(SfxRequest &rReq)
70 DeactivateCurrentFunction();
72 OutlinerView* pOutlinerView = pOlView->GetViewByWindow( GetActiveWindow() );
73 sal_uInt16 nSId = rReq.GetSlot();
75 switch( nSId )
77 case SID_ATTR_ZOOM:
79 const SfxItemSet* pArgs = rReq.GetArgs();
81 if ( pArgs )
83 SvxZoomType eZT = pArgs->Get( SID_ATTR_ZOOM ).GetType();
84 switch( eZT )
86 case SvxZoomType::PERCENT:
87 SetZoom( static_cast<::tools::Long>( pArgs->Get( SID_ATTR_ZOOM ).GetValue()) );
88 Invalidate( SID_ATTR_ZOOM );
89 Invalidate( SID_ATTR_ZOOMSLIDER );
90 break;
91 default:
92 break;
94 rReq.Done();
96 else
98 // open the zoom dialog here
99 SetCurrentFunction( FuScale::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
101 Cancel();
103 break;
105 case SID_ATTR_ZOOMSLIDER:
107 const SfxItemSet* pArgs = rReq.GetArgs();
109 const SfxUInt16Item* pScale = (pArgs && pArgs->Count () == 1) ?
110 rReq.GetArg<SfxUInt16Item>(SID_ATTR_ZOOMSLIDER) : nullptr;
111 if (pScale && CHECK_RANGE (5, pScale->GetValue (), 3000))
113 SetZoom (pScale->GetValue ());
115 SfxBindings& rBindings = GetViewFrame()->GetBindings();
116 rBindings.Invalidate( SID_ATTR_ZOOM );
117 rBindings.Invalidate( SID_ZOOM_IN );
118 rBindings.Invalidate( SID_ZOOM_OUT );
119 rBindings.Invalidate( SID_ATTR_ZOOMSLIDER );
123 Cancel();
124 rReq.Done ();
125 break;
128 case SID_ZOOM_IN:
130 SetZoom( std::min<::tools::Long>( GetActiveWindow()->GetZoom() * 2, GetActiveWindow()->GetMaxZoom() ) );
131 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0),
132 GetActiveWindow()->GetOutputSizePixel()) );
133 mpZoomList->InsertZoomRect(aVisAreaWin);
134 Invalidate( SID_ATTR_ZOOM );
135 Invalidate( SID_ZOOM_IN );
136 Invalidate(SID_ZOOM_OUT);
137 Invalidate( SID_ATTR_ZOOMSLIDER );
138 Cancel();
139 rReq.Done();
141 break;
143 case SID_SIZE_REAL:
145 SetZoom( 100 );
146 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0),
147 GetActiveWindow()->GetOutputSizePixel()) );
148 mpZoomList->InsertZoomRect(aVisAreaWin);
149 Invalidate( SID_ATTR_ZOOM );
150 Invalidate( SID_ATTR_ZOOMSLIDER );
151 Cancel();
152 rReq.Done();
154 break;
156 case SID_ZOOM_OUT:
158 SetZoom( std::max<::tools::Long>( GetActiveWindow()->GetZoom() / 2, GetActiveWindow()->GetMinZoom() ) );
159 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0),
160 GetActiveWindow()->GetOutputSizePixel()) );
161 mpZoomList->InsertZoomRect(aVisAreaWin);
162 Invalidate( SID_ATTR_ZOOM );
163 Invalidate( SID_ZOOM_OUT);
164 Invalidate( SID_ZOOM_IN );
165 Invalidate( SID_ATTR_ZOOMSLIDER );
166 Cancel();
167 rReq.Done();
169 break;
171 case SID_OUTLINE_COLLAPSE_ALL:
173 pOutlinerView->CollapseAll();
174 Cancel();
175 rReq.Done();
177 break;
179 case SID_OUTLINE_COLLAPSE:
181 pOutlinerView->Collapse();
182 Cancel();
183 rReq.Done();
185 break;
187 case SID_OUTLINE_EXPAND_ALL:
189 pOutlinerView->ExpandAll();
190 Cancel();
191 rReq.Done();
193 break;
195 case SID_OUTLINE_EXPAND:
197 pOutlinerView->Expand();
198 Cancel();
199 rReq.Done();
201 break;
203 case SID_OUTLINE_FORMAT:
205 ::Outliner* pOutl = pOutlinerView->GetOutliner();
206 pOutl->SetFlatMode( !pOutl->IsFlatMode() );
207 Invalidate( SID_COLORVIEW );
208 Cancel();
209 rReq.Done();
211 break;
213 case SID_SELECTALL:
215 ::Outliner& rOutl = pOlView->GetOutliner();
216 sal_Int32 nParaCount = rOutl.GetParagraphCount();
217 if (nParaCount > 0)
219 pOutlinerView->SelectRange( 0, nParaCount );
221 Cancel();
223 break;
225 case SID_PRESENTATION:
226 case SID_PRESENTATION_CURRENT_SLIDE:
227 case SID_REHEARSE_TIMINGS:
229 pOlView->PrepareClose();
230 slideshowhelp::ShowSlideShow(rReq, *GetDoc());
231 Cancel();
232 rReq.Done();
234 break;
236 case SID_COLORVIEW:
238 ::Outliner* pOutl = pOutlinerView->GetOutliner();
239 EEControlBits nCntrl = pOutl->GetControlWord();
241 if ( !(nCntrl & EEControlBits::NOCOLORS) )
243 // color view is enabled: disable
244 pOutl->SetControlWord(nCntrl | EEControlBits::NOCOLORS);
246 else
248 // color view is disabled: enable
249 pOutl->SetControlWord(nCntrl & ~EEControlBits::NOCOLORS);
252 InvalidateWindows();
253 Invalidate( SID_COLORVIEW );
254 Cancel();
255 rReq.Done();
257 break;
259 case SID_STYLE_EDIT:
260 case SID_STYLE_UPDATE_BY_EXAMPLE:
262 if( rReq.GetArgs() )
264 SetCurrentFunction( FuTemplate::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
265 Cancel();
268 rReq.Ignore ();
270 break;
272 case SID_PRESENTATION_DLG:
274 SetCurrentFunction( FuSlideShowDlg::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
275 Cancel();
277 break;
279 case SID_REMOTE_DLG:
281 #ifdef ENABLE_SDREMOTE
282 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
283 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateRemoteDialog(GetFrameWeld()));
284 pDlg->Execute();
285 #endif
287 break;
289 case SID_CUSTOMSHOW_DLG:
291 SetCurrentFunction( FuCustomShowDlg::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
292 Cancel();
294 break;
296 case SID_PHOTOALBUM:
298 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
299 vcl::Window* pWin = GetActiveWindow();
300 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSdPhotoAlbumDialog(
301 pWin ? pWin->GetFrameWeld() : nullptr,
302 GetDoc()));
304 pDlg->Execute();
306 Cancel();
307 rReq.Ignore ();
309 break;
312 if(HasCurrentFunction())
313 GetCurrentFunction()->Activate();
315 Invalidate( SID_OUTLINE_COLLAPSE_ALL );
316 Invalidate( SID_OUTLINE_COLLAPSE );
317 Invalidate( SID_OUTLINE_EXPAND_ALL );
318 Invalidate( SID_OUTLINE_EXPAND );
320 SfxBindings& rBindings = GetViewFrame()->GetBindings();
321 rBindings.Invalidate( SID_OUTLINE_LEFT );
322 rBindings.Invalidate( SID_OUTLINE_RIGHT );
323 rBindings.Invalidate( SID_OUTLINE_UP );
324 rBindings.Invalidate( SID_OUTLINE_DOWN );
326 Invalidate( SID_OUTLINE_FORMAT );
327 Invalidate( SID_COLORVIEW );
328 Invalidate(SID_CUT);
329 Invalidate(SID_COPY);
330 Invalidate(SID_PASTE);
331 Invalidate(SID_PASTE_UNFORMATTED);
334 void OutlineViewShell::FuTemporaryModify(SfxRequest &rReq)
336 sal_uInt16 nSId = rReq.GetSlot();
337 std::unique_ptr<OutlineViewModelChangeGuard, o3tl::default_delete<OutlineViewModelChangeGuard>> aGuard;
338 if (nSId != SID_OUTLINE_BULLET && nSId != FN_SVX_SET_BULLET && nSId != FN_SVX_SET_NUMBER)
340 aGuard.reset( new OutlineViewModelChangeGuard(*pOlView) );
342 DeactivateCurrentFunction();
344 OutlinerView* pOutlinerView = pOlView->GetViewByWindow( GetActiveWindow() );
345 //sal_uInt16 nSId = rReq.GetSlot();
347 switch( nSId )
349 case SID_HYPERLINK_SETLINK:
351 const SfxItemSet* pReqArgs = rReq.GetArgs();
353 if (pReqArgs)
355 const SvxHyperlinkItem* pHLItem =
356 &pReqArgs->Get(SID_HYPERLINK_SETLINK);
358 SvxFieldItem aURLItem(SvxURLField(pHLItem->GetURL(),
359 pHLItem->GetName(),
360 SvxURLFormat::Repr), EE_FEATURE_FIELD);
361 ESelection aSel( pOutlinerView->GetSelection() );
362 pOutlinerView->InsertField(aURLItem);
363 if ( aSel.nStartPos <= aSel.nEndPos )
364 aSel.nEndPos = aSel.nStartPos + 1;
365 else
366 aSel.nStartPos = aSel.nEndPos + 1;
367 pOutlinerView->SetSelection( aSel );
370 Cancel();
371 rReq.Ignore ();
373 break;
375 case FN_INSERT_SOFT_HYPHEN:
376 case FN_INSERT_HARDHYPHEN:
377 case FN_INSERT_HARD_SPACE:
378 case FN_INSERT_NNBSP:
379 case SID_INSERT_RLM :
380 case SID_INSERT_LRM :
381 case SID_INSERT_ZWNBSP :
382 case SID_INSERT_ZWSP:
383 case SID_CHARMAP:
385 SetCurrentFunction( FuBullet::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
386 Cancel();
388 break;
390 case SID_OUTLINE_BULLET:
391 case FN_SVX_SET_BULLET:
392 case FN_SVX_SET_NUMBER:
394 SetCurrentFunction( FuBulletAndPosition::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
395 Cancel();
397 break;
399 case SID_THESAURUS:
401 SetCurrentFunction( FuThesaurus::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
402 Cancel();
403 rReq.Ignore ();
405 break;
407 case SID_CHAR_DLG_EFFECT:
408 case SID_CHAR_DLG:
410 SetCurrentFunction( FuChar::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
411 Cancel();
413 break;
415 case SID_INSERTFILE:
417 SetCurrentFunction( FuInsertFile::Create(this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq) );
418 Cancel();
420 break;
422 case SID_PRESENTATIONOBJECT:
424 SetCurrentFunction( FuPresentationObjects::Create(this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq) );
425 Cancel();
427 break;
429 case SID_SET_DEFAULT:
431 pOutlinerView->RemoveAttribs(true); // sal_True = also paragraph attributes
432 Cancel();
433 rReq.Done();
435 break;
437 case SID_SUMMARY_PAGE:
439 pOlView->SetSelectedPages();
440 SetCurrentFunction( FuSummaryPage::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
441 pOlView->GetOutliner().Clear();
442 pOlView->FillOutliner();
443 pOlView->GetActualPage();
444 Cancel();
446 break;
448 case SID_EXPAND_PAGE:
450 pOlView->SetSelectedPages();
451 SetCurrentFunction( FuExpandPage::Create( this, GetActiveWindow(), pOlView.get(), GetDoc(), rReq ) );
452 pOlView->GetOutliner().Clear();
453 pOlView->FillOutliner();
454 pOlView->GetActualPage();
455 Cancel();
457 break;
459 case SID_INSERT_FLD_DATE_FIX:
460 case SID_INSERT_FLD_DATE_VAR:
461 case SID_INSERT_FLD_TIME_FIX:
462 case SID_INSERT_FLD_TIME_VAR:
463 case SID_INSERT_FLD_AUTHOR:
464 case SID_INSERT_FLD_PAGE:
465 case SID_INSERT_FLD_PAGE_TITLE:
466 case SID_INSERT_FLD_PAGES:
467 case SID_INSERT_FLD_FILE:
469 std::unique_ptr<SvxFieldItem> pFieldItem;
471 switch( nSId )
473 case SID_INSERT_FLD_DATE_FIX:
474 pFieldItem.reset(new SvxFieldItem(
475 SvxDateField( Date( Date::SYSTEM ), SvxDateType::Fix ), EE_FEATURE_FIELD ));
476 break;
478 case SID_INSERT_FLD_DATE_VAR:
479 pFieldItem.reset(new SvxFieldItem( SvxDateField(), EE_FEATURE_FIELD ));
480 break;
482 case SID_INSERT_FLD_TIME_FIX:
483 pFieldItem.reset(new SvxFieldItem(
484 SvxExtTimeField( ::tools::Time( ::tools::Time::SYSTEM ), SvxTimeType::Fix ), EE_FEATURE_FIELD ));
485 break;
487 case SID_INSERT_FLD_TIME_VAR:
488 pFieldItem.reset(new SvxFieldItem( SvxExtTimeField(), EE_FEATURE_FIELD ));
489 break;
491 case SID_INSERT_FLD_AUTHOR:
493 SvtUserOptions aUserOptions;
494 pFieldItem.reset(new SvxFieldItem(
495 SvxAuthorField(
496 aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID() )
497 , EE_FEATURE_FIELD ));
499 break;
501 case SID_INSERT_FLD_PAGE:
502 pFieldItem.reset(new SvxFieldItem( SvxPageField(), EE_FEATURE_FIELD ));
503 break;
505 case SID_INSERT_FLD_PAGE_TITLE:
506 pFieldItem.reset(new SvxFieldItem( SvxPageTitleField(), EE_FEATURE_FIELD));
507 break;
509 case SID_INSERT_FLD_PAGES:
510 pFieldItem.reset(new SvxFieldItem( SvxPagesField(), EE_FEATURE_FIELD ));
511 break;
513 case SID_INSERT_FLD_FILE:
515 OUString aName;
516 if( GetDocSh()->HasName() )
517 aName = GetDocSh()->GetMedium()->GetName();
518 //else
519 // aName = GetDocSh()->GetName();
520 pFieldItem.reset(new SvxFieldItem( SvxExtFileField( aName ), EE_FEATURE_FIELD ));
522 break;
525 const SvxFieldItem* pOldFldItem = pOutlinerView->GetFieldAtSelection();
527 if( pOldFldItem && ( nullptr != dynamic_cast< const SvxURLField *>( pOldFldItem->GetField() ) ||
528 nullptr != dynamic_cast< const SvxDateField *>( pOldFldItem->GetField() ) ||
529 nullptr != dynamic_cast< const SvxTimeField *>( pOldFldItem->GetField() ) ||
530 nullptr != dynamic_cast< const SvxExtTimeField *>( pOldFldItem->GetField() ) ||
531 nullptr != dynamic_cast< const SvxExtFileField *>( pOldFldItem->GetField() ) ||
532 nullptr != dynamic_cast< const SvxAuthorField *>( pOldFldItem->GetField() ) ||
533 nullptr != dynamic_cast< const SvxPageField *>( pOldFldItem->GetField() ) ||
534 nullptr != dynamic_cast< const SvxPagesField *>( pOldFldItem->GetField() )) )
536 // select field, so it gets deleted on Insert
537 ESelection aSel = pOutlinerView->GetSelection();
538 if( aSel.nStartPos == aSel.nEndPos )
539 aSel.nEndPos++;
540 pOutlinerView->SetSelection( aSel );
543 if( pFieldItem )
544 pOutlinerView->InsertField( *pFieldItem );
546 pFieldItem.reset();
548 Cancel();
549 rReq.Ignore ();
551 break;
553 case SID_MODIFY_FIELD:
555 const SvxFieldItem* pFldItem = pOutlinerView->GetFieldAtSelection();
557 if( pFldItem && (nullptr != dynamic_cast< const SvxDateField *>( pFldItem->GetField() ) ||
558 nullptr != dynamic_cast< const SvxAuthorField *>( pFldItem->GetField() ) ||
559 nullptr != dynamic_cast< const SvxExtFileField *>( pFldItem->GetField() ) ||
560 nullptr != dynamic_cast< const SvxExtTimeField *>( pFldItem->GetField() ) ) )
562 // Dialog...
563 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
564 vcl::Window* pWin = GetActiveWindow();
565 ScopedVclPtr<AbstractSdModifyFieldDlg> pDlg(pFact->CreateSdModifyFieldDlg(pWin ? pWin->GetFrameWeld() : nullptr, pFldItem->GetField(), pOutlinerView->GetAttribs() ));
566 if( pDlg->Execute() == RET_OK )
568 std::unique_ptr<SvxFieldData> pField(pDlg->GetField());
569 if( pField )
571 SvxFieldItem aFieldItem( *pField, EE_FEATURE_FIELD );
572 //pOLV->DeleteSelected(); <-- unfortunately missing!
573 // select field, so it gets deleted on Insert
574 ESelection aSel = pOutlinerView->GetSelection();
575 bool bSel = true;
576 if( aSel.nStartPos == aSel.nEndPos )
578 bSel = false;
579 aSel.nEndPos++;
581 pOutlinerView->SetSelection( aSel );
583 pOutlinerView->InsertField( aFieldItem );
585 // reset selection to original state
586 if( !bSel )
587 aSel.nEndPos--;
588 pOutlinerView->SetSelection( aSel );
590 pField.reset();
593 SfxItemSet aSet( pDlg->GetItemSet() );
594 if( aSet.Count() )
596 pOutlinerView->SetAttribs( aSet );
598 ::Outliner* pOutliner = pOutlinerView->GetOutliner();
599 if( pOutliner )
600 pOutliner->UpdateFields();
605 Cancel();
606 rReq.Ignore ();
608 break;
611 if(HasCurrentFunction())
612 GetCurrentFunction()->Activate();
614 Invalidate( SID_OUTLINE_COLLAPSE_ALL );
615 Invalidate( SID_OUTLINE_COLLAPSE );
616 Invalidate( SID_OUTLINE_EXPAND_ALL );
617 Invalidate( SID_OUTLINE_EXPAND );
619 SfxBindings& rBindings = GetViewFrame()->GetBindings();
620 rBindings.Invalidate( SID_OUTLINE_LEFT );
621 rBindings.Invalidate( SID_OUTLINE_RIGHT );
622 rBindings.Invalidate( SID_OUTLINE_UP );
623 rBindings.Invalidate( SID_OUTLINE_DOWN );
625 Invalidate( SID_OUTLINE_FORMAT );
626 Invalidate( SID_COLORVIEW );
627 Invalidate(SID_CUT);
628 Invalidate(SID_COPY);
629 Invalidate(SID_PASTE);
630 Invalidate(SID_PASTE_UNFORMATTED);
633 } // end of namespace sd
635 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */