bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / view / outlnvs2.cxx
blob7806b653dfea717814b9afc00ad3c31540a78df7
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 <com/sun/star/presentation/XPresentation2.hpp>
23 #include <com/sun/star/beans/PropertyValue.hpp>
24 #include <com/sun/star/uno/Any.hxx>
26 #include "app.hrc"
27 #include <svx/hlnkitem.hxx>
28 #include <sfx2/docfile.hxx>
29 #include <sfx2/dispatch.hxx>
30 #include <sfx2/request.hxx>
31 #include <svl/eitem.hxx>
32 #include <sfx2/zoomitem.hxx>
33 #include <svx/svxids.hrc>
34 #include <vcl/msgbox.hxx>
35 #include <editeng/eeitem.hxx>
36 #include <editeng/flditem.hxx>
37 #include <editeng/editstat.hxx>
38 #include "optsitem.hxx"
39 #include <unotools/useroptions.hxx>
41 #include <sfx2/viewfrm.hxx>
42 #include "Outliner.hxx"
43 #include "Window.hxx"
44 #include "fubullet.hxx"
45 #include "fuolbull.hxx"
46 #include "FrameView.hxx"
47 #include "fuzoom.hxx"
48 #include "fuscale.hxx"
49 #include "fuchar.hxx"
50 #include "fuinsfil.hxx"
51 #include "fuprobjs.hxx"
52 #include "futhes.hxx"
53 #include "futempl.hxx"
54 #include "fusldlg.hxx"
55 #include "zoomlist.hxx"
56 #include "fuexpand.hxx"
57 #include "fusumry.hxx"
58 #include "fucushow.hxx"
59 #include "drawdoc.hxx"
60 #include "sdattr.hxx"
61 #include "ViewShellBase.hxx"
62 #include "sdabstdlg.hxx"
63 #include "framework/FrameworkHelper.hxx"
64 #include "DrawViewShell.hxx"
65 #include "slideshow.hxx"
66 #include <boost/scoped_ptr.hpp>
68 using namespace ::com::sun::star::uno;
69 using namespace ::com::sun::star::presentation;
70 using namespace ::com::sun::star::beans;
72 namespace sd {
74 /************************************************************************/
76 /**
77 * SfxRequests for temporary functions
80 void OutlineViewShell::FuTemporary(SfxRequest &rReq)
82 DeactivateCurrentFunction();
84 OutlinerView* pOutlinerView = pOlView->GetViewByWindow( GetActiveWindow() );
85 sal_uInt16 nSId = rReq.GetSlot();
87 switch( nSId )
89 case SID_ATTR_ZOOM:
91 const SfxItemSet* pArgs = rReq.GetArgs();
93 if ( pArgs )
95 SvxZoomType eZT = static_cast<const SvxZoomItem&>( pArgs->
96 Get( SID_ATTR_ZOOM ) ).GetType();
97 switch( eZT )
99 case SvxZoomType::PERCENT:
100 SetZoom( (long) static_cast<const SvxZoomItem&>( pArgs->
101 Get( SID_ATTR_ZOOM ) ).GetValue() );
102 Invalidate( SID_ATTR_ZOOM );
103 Invalidate( SID_ATTR_ZOOMSLIDER );
104 break;
105 default:
106 break;
108 rReq.Done();
110 else
112 // open the zoom dialog here
113 SetCurrentFunction( FuScale::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
115 Cancel();
117 break;
119 case SID_ATTR_ZOOMSLIDER:
121 const SfxItemSet* pArgs = rReq.GetArgs();
123 if (pArgs && pArgs->Count () == 1 )
125 SFX_REQUEST_ARG (rReq, pScale, SfxUInt16Item, SID_ATTR_ZOOMSLIDER, false);
126 if (CHECK_RANGE (5, pScale->GetValue (), 3000))
128 SetZoom (pScale->GetValue ());
130 SfxBindings& rBindings = GetViewFrame()->GetBindings();
131 rBindings.Invalidate( SID_ATTR_ZOOM );
132 rBindings.Invalidate( SID_ZOOM_IN );
133 rBindings.Invalidate( SID_ZOOM_OUT );
134 rBindings.Invalidate( SID_ATTR_ZOOMSLIDER );
139 Cancel();
140 rReq.Done ();
141 break;
144 case SID_ZOOM_OUT:
146 SetZoom( std::min( (long) ( GetActiveWindow()->GetZoom() * 2 ), (long) GetActiveWindow()->GetMaxZoom() ) );
147 Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( Rectangle( Point(0,0),
148 GetActiveWindow()->GetOutputSizePixel()) );
149 mpZoomList->InsertZoomRect(aVisAreaWin);
150 Invalidate( SID_ATTR_ZOOM );
151 Invalidate( SID_ZOOM_IN );
152 Invalidate( SID_ATTR_ZOOMSLIDER );
153 Cancel();
154 rReq.Done();
156 break;
158 case SID_SIZE_REAL:
160 SetZoom( 100 );
161 Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( Rectangle( Point(0,0),
162 GetActiveWindow()->GetOutputSizePixel()) );
163 mpZoomList->InsertZoomRect(aVisAreaWin);
164 Invalidate( SID_ATTR_ZOOM );
165 Invalidate( SID_ATTR_ZOOMSLIDER );
166 Cancel();
167 rReq.Done();
169 break;
171 case SID_ZOOM_IN:
173 SetZoom( std::max( (long) ( GetActiveWindow()->GetZoom() / 2 ), (long) GetActiveWindow()->GetMinZoom() ) );
174 Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( Rectangle( Point(0,0),
175 GetActiveWindow()->GetOutputSizePixel()) );
176 mpZoomList->InsertZoomRect(aVisAreaWin);
177 Invalidate( SID_ATTR_ZOOM );
178 Invalidate( SID_ZOOM_OUT);
179 Invalidate( SID_ZOOM_IN );
180 Invalidate( SID_ATTR_ZOOMSLIDER );
181 Cancel();
182 rReq.Done();
184 break;
186 case SID_OUTLINE_COLLAPSE_ALL:
188 pOutlinerView->CollapseAll();
189 Cancel();
190 rReq.Done();
192 break;
194 case SID_OUTLINE_COLLAPSE:
196 pOutlinerView->Collapse();
197 Cancel();
198 rReq.Done();
200 break;
202 case SID_OUTLINE_EXPAND_ALL:
204 pOutlinerView->ExpandAll();
205 Cancel();
206 rReq.Done();
208 break;
210 case SID_OUTLINE_EXPAND:
212 pOutlinerView->Expand();
213 Cancel();
214 rReq.Done();
216 break;
218 case SID_OUTLINE_FORMAT:
220 ::Outliner* pOutl = pOutlinerView->GetOutliner();
221 pOutl->SetFlatMode( !pOutl->IsFlatMode() );
222 Invalidate( SID_COLORVIEW );
223 Cancel();
224 rReq.Done();
226 break;
228 case SID_SELECTALL:
230 ::Outliner& rOutl = pOlView->GetOutliner();
231 sal_Int32 nParaCount = rOutl.GetParagraphCount();
232 if (nParaCount > 0)
234 pOutlinerView->SelectRange( 0, nParaCount );
236 Cancel();
238 break;
240 case SID_PRESENTATION:
241 case SID_PRESENTATION_CURRENT_SLIDE:
242 case SID_REHEARSE_TIMINGS:
244 pOlView->PrepareClose();
245 ShowSlideShow(rReq);
246 Cancel();
247 rReq.Done();
249 break;
251 case SID_COLORVIEW:
253 ::Outliner* pOutl = pOutlinerView->GetOutliner();
254 EEControlBits nCntrl = pOutl->GetControlWord();
256 if ( !(nCntrl & EEControlBits::NOCOLORS) )
258 // color view is enabled: disable
259 pOutl->SetControlWord(nCntrl | EEControlBits::NOCOLORS);
261 else
263 // color view is disabled: enable
264 pOutl->SetControlWord(nCntrl & ~EEControlBits::NOCOLORS);
267 InvalidateWindows();
268 Invalidate( SID_COLORVIEW );
269 Cancel();
270 rReq.Done();
272 break;
274 case SID_STYLE_EDIT:
275 case SID_STYLE_UPDATE_BY_EXAMPLE:
277 if( rReq.GetArgs() )
279 SetCurrentFunction( FuTemplate::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
280 Cancel();
283 rReq.Ignore ();
285 break;
287 case SID_PRESENTATION_DLG:
289 SetCurrentFunction( FuSlideShowDlg::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
290 Cancel();
292 break;
294 case SID_REMOTE_DLG:
296 #ifdef ENABLE_SDREMOTE
297 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
298 VclAbstractDialog* pDlg = pFact ? pFact->CreateRemoteDialog(GetActiveWindow()) : 0;
299 if (pDlg)
300 pDlg->Execute();
301 #endif
303 break;
305 case SID_CUSTOMSHOW_DLG:
307 SetCurrentFunction( FuCustomShowDlg::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
308 Cancel();
310 break;
312 case SID_PHOTOALBUM:
314 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
315 boost::scoped_ptr<VclAbstractDialog> pDlg(pFact ? pFact->CreateSdPhotoAlbumDialog(
316 GetActiveWindow(),
317 GetDoc()) : 0);
319 if (pDlg)
321 pDlg->Execute();
322 pDlg.reset();
324 Cancel();
325 rReq.Ignore ();
327 break;
330 if(HasCurrentFunction())
331 GetCurrentFunction()->Activate();
333 Invalidate( SID_OUTLINE_COLLAPSE_ALL );
334 Invalidate( SID_OUTLINE_COLLAPSE );
335 Invalidate( SID_OUTLINE_EXPAND_ALL );
336 Invalidate( SID_OUTLINE_EXPAND );
338 SfxBindings& rBindings = GetViewFrame()->GetBindings();
339 rBindings.Invalidate( SID_OUTLINE_LEFT );
340 rBindings.Invalidate( SID_OUTLINE_RIGHT );
341 rBindings.Invalidate( SID_OUTLINE_UP );
342 rBindings.Invalidate( SID_OUTLINE_DOWN );
344 Invalidate( SID_OUTLINE_FORMAT );
345 Invalidate( SID_COLORVIEW );
346 Invalidate(SID_CUT);
347 Invalidate(SID_COPY);
348 Invalidate(SID_PASTE);
349 Invalidate(SID_PASTE_UNFORMATTED);
352 void OutlineViewShell::ShowSlideShow(SfxRequest& rReq)
354 slideshowhelp::ShowSlideShow(rReq, *GetDoc());
357 void OutlineViewShell::FuTemporaryModify(SfxRequest &rReq)
359 sal_uInt16 nSId = rReq.GetSlot();
360 boost::scoped_ptr< OutlineViewModelChangeGuard > aGuard;
361 if (nSId != SID_OUTLINE_BULLET && nSId != FN_SVX_SET_BULLET && nSId != FN_SVX_SET_NUMBER)
363 aGuard.reset( new OutlineViewModelChangeGuard(*pOlView) );
365 DeactivateCurrentFunction();
367 OutlinerView* pOutlinerView = pOlView->GetViewByWindow( GetActiveWindow() );
368 //sal_uInt16 nSId = rReq.GetSlot();
370 switch( nSId )
372 case SID_HYPERLINK_SETLINK:
374 const SfxItemSet* pReqArgs = rReq.GetArgs();
376 if (pReqArgs)
378 const SvxHyperlinkItem* pHLItem =
379 static_cast<const SvxHyperlinkItem*>( &pReqArgs->Get(SID_HYPERLINK_SETLINK) );
381 SvxFieldItem aURLItem(SvxURLField(pHLItem->GetURL(),
382 pHLItem->GetName(),
383 SVXURLFORMAT_REPR), EE_FEATURE_FIELD);
384 ESelection aSel( pOutlinerView->GetSelection() );
385 pOutlinerView->InsertField(aURLItem);
386 if ( aSel.nStartPos <= aSel.nEndPos )
387 aSel.nEndPos = aSel.nStartPos + 1;
388 else
389 aSel.nStartPos = aSel.nEndPos + 1;
390 pOutlinerView->SetSelection( aSel );
393 Cancel();
394 rReq.Ignore ();
396 break;
398 case FN_INSERT_SOFT_HYPHEN:
399 case FN_INSERT_HARDHYPHEN:
400 case FN_INSERT_HARD_SPACE:
401 case SID_INSERT_RLM :
402 case SID_INSERT_LRM :
403 case SID_INSERT_ZWNBSP :
404 case SID_INSERT_ZWSP:
405 case SID_CHARMAP:
407 SetCurrentFunction( FuBullet::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
408 Cancel();
410 break;
412 case SID_OUTLINE_BULLET:
413 case FN_SVX_SET_BULLET:
414 case FN_SVX_SET_NUMBER:
416 SetCurrentFunction( FuOutlineBullet::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
417 Cancel();
419 break;
421 case SID_THESAURUS:
423 SetCurrentFunction( FuThesaurus::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
424 Cancel();
425 rReq.Ignore ();
427 break;
429 case SID_CHAR_DLG_EFFECT:
430 case SID_CHAR_DLG:
432 SetCurrentFunction( FuChar::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
433 Cancel();
435 break;
437 case SID_INSERTFILE:
439 SetCurrentFunction( FuInsertFile::Create(this, GetActiveWindow(), pOlView, GetDoc(), rReq) );
440 Cancel();
442 break;
444 case SID_PRESENTATIONOBJECT:
446 SetCurrentFunction( FuPresentationObjects::Create(this, GetActiveWindow(), pOlView, GetDoc(), rReq) );
447 Cancel();
449 break;
451 case SID_SET_DEFAULT:
453 pOutlinerView->RemoveAttribs(true); // sal_True = also paragraph attributes
454 Cancel();
455 rReq.Done();
457 break;
459 case SID_SUMMARY_PAGE:
461 pOlView->SetSelectedPages();
462 SetCurrentFunction( FuSummaryPage::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
463 pOlView->GetOutliner().Clear();
464 pOlView->FillOutliner();
465 pOlView->GetActualPage();
466 Cancel();
468 break;
470 case SID_EXPAND_PAGE:
472 pOlView->SetSelectedPages();
473 SetCurrentFunction( FuExpandPage::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
474 pOlView->GetOutliner().Clear();
475 pOlView->FillOutliner();
476 pOlView->GetActualPage();
477 Cancel();
479 break;
481 case SID_INSERT_FLD_DATE_FIX:
482 case SID_INSERT_FLD_DATE_VAR:
483 case SID_INSERT_FLD_TIME_FIX:
484 case SID_INSERT_FLD_TIME_VAR:
485 case SID_INSERT_FLD_AUTHOR:
486 case SID_INSERT_FLD_PAGE:
487 case SID_INSERT_FLD_PAGE_TITLE:
488 case SID_INSERT_FLD_PAGES:
489 case SID_INSERT_FLD_FILE:
491 boost::scoped_ptr<SvxFieldItem> pFieldItem;
493 switch( nSId )
495 case SID_INSERT_FLD_DATE_FIX:
496 pFieldItem.reset(new SvxFieldItem(
497 SvxDateField( Date( Date::SYSTEM ), SVXDATETYPE_FIX ), EE_FEATURE_FIELD ));
498 break;
500 case SID_INSERT_FLD_DATE_VAR:
501 pFieldItem.reset(new SvxFieldItem( SvxDateField(), EE_FEATURE_FIELD ));
502 break;
504 case SID_INSERT_FLD_TIME_FIX:
505 pFieldItem.reset(new SvxFieldItem(
506 SvxExtTimeField( ::tools::Time( ::tools::Time::SYSTEM ), SVXTIMETYPE_FIX ), EE_FEATURE_FIELD ));
507 break;
509 case SID_INSERT_FLD_TIME_VAR:
510 pFieldItem.reset(new SvxFieldItem( SvxExtTimeField(), EE_FEATURE_FIELD ));
511 break;
513 case SID_INSERT_FLD_AUTHOR:
515 SvtUserOptions aUserOptions;
516 pFieldItem.reset(new SvxFieldItem(
517 SvxAuthorField(
518 aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID() )
519 , EE_FEATURE_FIELD ));
521 break;
523 case SID_INSERT_FLD_PAGE:
524 pFieldItem.reset(new SvxFieldItem( SvxPageField(), EE_FEATURE_FIELD ));
525 break;
527 case SID_INSERT_FLD_PAGE_TITLE:
528 pFieldItem.reset(new SvxFieldItem( SvxPageTitleField(), EE_FEATURE_FIELD));
529 break;
531 case SID_INSERT_FLD_PAGES:
532 pFieldItem.reset(new SvxFieldItem( SvxPagesField(), EE_FEATURE_FIELD ));
533 break;
535 case SID_INSERT_FLD_FILE:
537 OUString aName;
538 if( GetDocSh()->HasName() )
539 aName = GetDocSh()->GetMedium()->GetName();
540 //else
541 // aName = GetDocSh()->GetName();
542 pFieldItem.reset(new SvxFieldItem( SvxExtFileField( aName ), EE_FEATURE_FIELD ));
544 break;
547 const SvxFieldItem* pOldFldItem = pOutlinerView->GetFieldAtSelection();
549 if( pOldFldItem && ( pOldFldItem->GetField()->ISA( SvxURLField ) ||
550 pOldFldItem->GetField()->ISA( SvxDateField ) ||
551 pOldFldItem->GetField()->ISA( SvxTimeField ) ||
552 pOldFldItem->GetField()->ISA( SvxExtTimeField ) ||
553 pOldFldItem->GetField()->ISA( SvxExtFileField ) ||
554 pOldFldItem->GetField()->ISA( SvxAuthorField ) ||
555 pOldFldItem->GetField()->ISA( SvxPageField ) ||
556 pOldFldItem->GetField()->ISA( SvxPagesField )) )
558 // select field, so it gets deleted on Insert
559 ESelection aSel = pOutlinerView->GetSelection();
560 if( aSel.nStartPos == aSel.nEndPos )
561 aSel.nEndPos++;
562 pOutlinerView->SetSelection( aSel );
565 if( pFieldItem )
566 pOutlinerView->InsertField( *pFieldItem );
568 pFieldItem.reset();
570 Cancel();
571 rReq.Ignore ();
573 break;
575 case SID_MODIFY_FIELD:
577 const SvxFieldItem* pFldItem = pOutlinerView->GetFieldAtSelection();
579 if( pFldItem && (pFldItem->GetField()->ISA( SvxDateField ) ||
580 pFldItem->GetField()->ISA( SvxAuthorField ) ||
581 pFldItem->GetField()->ISA( SvxExtFileField ) ||
582 pFldItem->GetField()->ISA( SvxExtTimeField ) ) )
584 // Dialog...
585 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
586 boost::scoped_ptr<AbstractSdModifyFieldDlg> pDlg(pFact ? pFact->CreateSdModifyFieldDlg(GetActiveWindow(), pFldItem->GetField(), pOutlinerView->GetAttribs() ) : 0);
587 if( pDlg && (pDlg->Execute() == RET_OK) )
589 boost::scoped_ptr<SvxFieldData> pField(pDlg->GetField());
590 if( pField )
592 SvxFieldItem aFieldItem( *pField, EE_FEATURE_FIELD );
593 //pOLV->DeleteSelected(); <-- unfortunately missing!
594 // select field, so it gets deleted on Insert
595 ESelection aSel = pOutlinerView->GetSelection();
596 bool bSel = true;
597 if( aSel.nStartPos == aSel.nEndPos )
599 bSel = false;
600 aSel.nEndPos++;
602 pOutlinerView->SetSelection( aSel );
604 pOutlinerView->InsertField( aFieldItem );
606 // reset selection to original state
607 if( !bSel )
608 aSel.nEndPos--;
609 pOutlinerView->SetSelection( aSel );
611 pField.reset();
614 SfxItemSet aSet( pDlg->GetItemSet() );
615 if( aSet.Count() )
617 pOutlinerView->SetAttribs( aSet );
619 ::Outliner* pOutliner = pOutlinerView->GetOutliner();
620 if( pOutliner )
621 pOutliner->UpdateFields();
626 Cancel();
627 rReq.Ignore ();
629 break;
632 if(HasCurrentFunction())
633 GetCurrentFunction()->Activate();
635 Invalidate( SID_OUTLINE_COLLAPSE_ALL );
636 Invalidate( SID_OUTLINE_COLLAPSE );
637 Invalidate( SID_OUTLINE_EXPAND_ALL );
638 Invalidate( SID_OUTLINE_EXPAND );
640 SfxBindings& rBindings = GetViewFrame()->GetBindings();
641 rBindings.Invalidate( SID_OUTLINE_LEFT );
642 rBindings.Invalidate( SID_OUTLINE_RIGHT );
643 rBindings.Invalidate( SID_OUTLINE_UP );
644 rBindings.Invalidate( SID_OUTLINE_DOWN );
646 Invalidate( SID_OUTLINE_FORMAT );
647 Invalidate( SID_COLORVIEW );
648 Invalidate(SID_CUT);
649 Invalidate(SID_COPY);
650 Invalidate(SID_PASTE);
651 Invalidate(SID_PASTE_UNFORMATTED);
654 } // end of namespace sd
656 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */