xref: /AOO41X/main/sd/source/ui/view/outlnvs2.cxx (revision fe617e93560c0575040cf13b538ba840fa9e2479)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #include "OutlineViewShell.hxx"
28 
29 #include <com/sun/star/presentation/XPresentation2.hpp>
30 
31 #include "app.hrc"
32 #include <svx/hlnkitem.hxx>
33 #include <sfx2/docfile.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <sfx2/request.hxx>
36 #include <svl/eitem.hxx>
37 #ifndef _ZOOMITEM_HXX //autogen
38 #include <svx/zoomitem.hxx>
39 #endif
40 #include <vcl/msgbox.hxx>
41 #include <editeng/eeitem.hxx>
42 #include <editeng/flditem.hxx>
43 #include <editeng/editstat.hxx>
44 #include "optsitem.hxx"
45 #include <unotools/useroptions.hxx>
46 
47 #include <sfx2/viewfrm.hxx>
48 #include "Outliner.hxx"
49 #include "Window.hxx"
50 #include "OutlineViewShell.hxx"
51 #include "fubullet.hxx"
52 #include "fuolbull.hxx"
53 #include "FrameView.hxx"
54 #include "fuzoom.hxx"
55 #include "fuscale.hxx"
56 #include "fuchar.hxx"
57 #include "fuinsfil.hxx"
58 #include "fuprobjs.hxx"
59 #include "futhes.hxx"
60 #include "futempl.hxx"
61 #include "fusldlg.hxx"
62 #include "zoomlist.hxx"
63 #include "fuexpand.hxx"
64 #include "fusumry.hxx"
65 #include "fucushow.hxx"
66 #include "drawdoc.hxx"
67 #include "sdattr.hxx"
68 #include "ViewShellBase.hxx"
69 #include "sdabstdlg.hxx"
70 #include "framework/FrameworkHelper.hxx"
71 #include "DrawViewShell.hxx"
72 
73 using namespace ::com::sun::star::uno;
74 using namespace ::com::sun::star::presentation;
75 
76 namespace sd {
77 
78 
79 /************************************************************************/
80 
81 /*************************************************************************
82 |*
83 |* SfxRequests fuer temporaere Funktionen
84 |*
85 \************************************************************************/
86 
87 void OutlineViewShell::FuTemporary(SfxRequest &rReq)
88 {
89     DeactivateCurrentFunction();
90 
91     OutlinerView* pOutlinerView = pOlView->GetViewByWindow( GetActiveWindow() );
92     sal_uInt16 nSId = rReq.GetSlot();
93 
94     switch( nSId )
95     {
96         case SID_ATTR_ZOOM:
97         {
98             const SfxItemSet* pArgs = rReq.GetArgs();
99 
100             if ( pArgs )
101             {
102                 SvxZoomType eZT = ( ( const SvxZoomItem& ) pArgs->
103                                             Get( SID_ATTR_ZOOM ) ).GetType();
104                 switch( eZT )
105                 {
106                     case SVX_ZOOM_PERCENT:
107                         SetZoom( (long) ( ( const SvxZoomItem& ) pArgs->
108                                             Get( SID_ATTR_ZOOM ) ).GetValue() );
109                         Invalidate( SID_ATTR_ZOOM );
110                         Invalidate( SID_ATTR_ZOOMSLIDER );
111                         break;
112                     default:
113                         break;
114                 }
115                 rReq.Done();
116             }
117             else
118             {
119                 // hier den Zoom-Dialog oeffnen
120                 SetCurrentFunction( FuScale::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
121             }
122             Cancel();
123         }
124         break;
125 
126         case SID_ATTR_ZOOMSLIDER:
127         {
128             const SfxItemSet* pArgs = rReq.GetArgs();
129 
130             if (pArgs && pArgs->Count () == 1 )
131             {
132                 SFX_REQUEST_ARG (rReq, pScale, SfxUInt16Item, SID_ATTR_ZOOMSLIDER, sal_False);
133                 if (CHECK_RANGE (5, pScale->GetValue (), 3000))
134                 {
135                     SetZoom (pScale->GetValue ());
136 
137                     SfxBindings& rBindings = GetViewFrame()->GetBindings();
138                     rBindings.Invalidate( SID_ATTR_ZOOM );
139                     rBindings.Invalidate( SID_ZOOM_IN );
140                     rBindings.Invalidate( SID_ZOOM_OUT );
141                     rBindings.Invalidate( SID_ATTR_ZOOMSLIDER );
142 
143                 }
144             }
145 
146             Cancel();
147             rReq.Done ();
148             break;
149         }
150 
151         case SID_ZOOM_OUT:
152         {
153             SetCurrentFunction( FuZoom::Create(this, GetActiveWindow(), pOlView, GetDoc(), rReq) );
154             // Beendet sich selbst, kein Cancel() notwendig!
155             rReq.Done();
156         }
157         break;
158 
159         case SID_SIZE_REAL:
160         {
161             SetZoom( 100 );
162             Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( Rectangle( Point(0,0),
163                                              GetActiveWindow()->GetOutputSizePixel()) );
164             mpZoomList->InsertZoomRect(aVisAreaWin);
165             Invalidate( SID_ATTR_ZOOM );
166             Invalidate( SID_ATTR_ZOOMSLIDER );
167             Cancel();
168             rReq.Done();
169         }
170         break;
171 
172         case SID_ZOOM_IN:
173         {
174             SetZoom( Max( (long) ( GetActiveWindow()->GetZoom() / 2 ), (long) GetActiveWindow()->GetMinZoom() ) );
175             Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( Rectangle( Point(0,0),
176                                              GetActiveWindow()->GetOutputSizePixel()) );
177             mpZoomList->InsertZoomRect(aVisAreaWin);
178             Invalidate( SID_ATTR_ZOOM );
179             Invalidate( SID_ZOOM_OUT);
180             Invalidate( SID_ZOOM_IN );
181             Invalidate( SID_ATTR_ZOOMSLIDER );
182             Cancel();
183             rReq.Done();
184         }
185         break;
186 
187         case SID_OUTLINE_COLLAPSE_ALL:
188         {
189             pOutlinerView->CollapseAll();
190             Cancel();
191             rReq.Done();
192         }
193         break;
194 
195         case SID_OUTLINE_COLLAPSE:
196         {
197             pOutlinerView->Collapse();
198             Cancel();
199             rReq.Done();
200         }
201         break;
202 
203         case SID_OUTLINE_EXPAND_ALL:
204         {
205             pOutlinerView->ExpandAll();
206             Cancel();
207             rReq.Done();
208         }
209         break;
210 
211         case SID_OUTLINE_EXPAND:
212         {
213             pOutlinerView->Expand();
214             Cancel();
215             rReq.Done();
216         }
217         break;
218 
219         case SID_OUTLINE_FORMAT:
220         {
221             ::Outliner* pOutl = pOutlinerView->GetOutliner();
222             pOutl->SetFlatMode( !pOutl->IsFlatMode() );
223             Invalidate( SID_COLORVIEW );
224             Cancel();
225             rReq.Done();
226         }
227         break;
228 
229         case SID_SELECTALL:
230         {
231             ::Outliner* pOutl = pOlView->GetOutliner();
232             sal_uLong nParaCount = pOutl->GetParagraphCount();
233             if (nParaCount > 0)
234             {
235                 pOutlinerView->SelectRange( 0, (sal_uInt16) nParaCount );
236             }
237             Cancel();
238         }
239         break;
240 
241         case SID_PRESENTATION:
242         case SID_REHEARSE_TIMINGS:
243         {
244             pOlView->PrepareClose();
245 
246             Reference< XPresentation2 > xPresentation( GetDoc()->getPresentation() );
247             if( xPresentation.is() )
248             {
249                 if( ( SID_REHEARSE_TIMINGS != rReq.GetSlot() ) )
250                     xPresentation->start();
251                 else
252                     xPresentation->rehearseTimings();
253             }
254             Cancel();
255             rReq.Done();
256         }
257         break;
258 
259         case SID_COLORVIEW:
260         {
261             ::Outliner* pOutl = pOutlinerView->GetOutliner();
262             sal_uLong nCntrl = pOutl->GetControlWord();
263 
264             if ( !(nCntrl & EE_CNTRL_NOCOLORS) )
265             {
266                 // Farbansicht ist eingeschaltet: ausschalten
267                 pOutl->SetControlWord(nCntrl | EE_CNTRL_NOCOLORS);
268             }
269             else
270             {
271                 // Farbansicht ist ausgeschaltet: einschalten
272                 pOutl->SetControlWord(nCntrl & ~EE_CNTRL_NOCOLORS);
273             }
274 
275             InvalidateWindows();
276             Invalidate( SID_COLORVIEW );
277             Cancel();
278             rReq.Done();
279         }
280         break;
281 
282         case SID_STYLE_EDIT:
283         case SID_STYLE_UPDATE_BY_EXAMPLE:
284         {
285             if( rReq.GetArgs() )
286             {
287                 SetCurrentFunction( FuTemplate::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
288                 Cancel();
289             }
290 
291             rReq.Ignore ();
292         }
293         break;
294 
295         case SID_PRESENTATION_DLG:
296         {
297             SetCurrentFunction( FuSlideShowDlg::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
298             Cancel();
299         }
300         break;
301 
302         case SID_CUSTOMSHOW_DLG:
303         {
304             SetCurrentFunction( FuCustomShowDlg::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
305             Cancel();
306         }
307         break;
308     }
309 
310     if(HasCurrentFunction())
311         GetCurrentFunction()->Activate();
312 
313     Invalidate( SID_OUTLINE_COLLAPSE_ALL );
314     Invalidate( SID_OUTLINE_COLLAPSE );
315     Invalidate( SID_OUTLINE_EXPAND_ALL );
316     Invalidate( SID_OUTLINE_EXPAND );
317 
318     SfxBindings& rBindings = GetViewFrame()->GetBindings();
319     rBindings.Invalidate( SID_OUTLINE_LEFT );
320     rBindings.Invalidate( SID_OUTLINE_RIGHT );
321     rBindings.Invalidate( SID_OUTLINE_UP );
322     rBindings.Invalidate( SID_OUTLINE_DOWN );
323 
324     Invalidate( SID_OUTLINE_FORMAT );
325     Invalidate( SID_COLORVIEW );
326     Invalidate(SID_CUT);
327     Invalidate(SID_COPY);
328     Invalidate(SID_PASTE);
329 }
330 
331 void OutlineViewShell::FuTemporaryModify(SfxRequest &rReq)
332 {
333     OutlineViewModelChangeGuard aGuard( *pOlView );
334 
335     DeactivateCurrentFunction();
336 
337     OutlinerView* pOutlinerView = pOlView->GetViewByWindow( GetActiveWindow() );
338     sal_uInt16 nSId = rReq.GetSlot();
339 
340     switch( nSId )
341     {
342         case SID_HYPERLINK_SETLINK:
343         {
344             const SfxItemSet* pReqArgs = rReq.GetArgs();
345 
346             if (pReqArgs)
347             {
348                 SvxHyperlinkItem* pHLItem =
349                 (SvxHyperlinkItem*) &pReqArgs->Get(SID_HYPERLINK_SETLINK);
350 
351                 SvxFieldItem aURLItem(SvxURLField(pHLItem->GetURL(),
352                                                   pHLItem->GetName(),
353                                                   SVXURLFORMAT_REPR), EE_FEATURE_FIELD);
354                 ESelection aSel( pOutlinerView->GetSelection() );
355                 pOutlinerView->InsertField(aURLItem);
356                 if ( aSel.nStartPos <= aSel.nEndPos )
357                     aSel.nEndPos = aSel.nStartPos + 1;
358                 else
359                     aSel.nStartPos = aSel.nEndPos + 1;
360                 pOutlinerView->SetSelection( aSel );
361             }
362 
363             Cancel();
364             rReq.Ignore ();
365         }
366         break;
367 
368         case FN_INSERT_SOFT_HYPHEN:
369         case FN_INSERT_HARDHYPHEN:
370         case FN_INSERT_HARD_SPACE:
371         case SID_INSERT_RLM :
372         case SID_INSERT_LRM :
373         case SID_INSERT_ZWNBSP :
374         case SID_INSERT_ZWSP:
375         case SID_CHARMAP:
376         {
377             SetCurrentFunction( FuBullet::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
378             Cancel();
379         }
380         break;
381 
382         case SID_OUTLINE_BULLET:
383         {
384             SetCurrentFunction( FuOutlineBullet::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
385             Cancel();
386         }
387         break;
388 
389         case SID_THESAURUS:
390         {
391             SetCurrentFunction( FuThesaurus::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
392             Cancel();
393             rReq.Ignore ();
394         }
395         break;
396 
397         case SID_CHAR_DLG_EFFECT:
398         case SID_CHAR_DLG:
399         {
400             SetCurrentFunction( FuChar::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
401             Cancel();
402         }
403         break;
404 
405         case SID_INSERTFILE:
406         {
407             SetCurrentFunction( FuInsertFile::Create(this, GetActiveWindow(), pOlView, GetDoc(), rReq) );
408             Cancel();
409         }
410         break;
411 
412         case SID_PRESENTATIONOBJECT:
413         {
414             SetCurrentFunction( FuPresentationObjects::Create(this, GetActiveWindow(), pOlView, GetDoc(), rReq) );
415             Cancel();
416         }
417         break;
418 
419         case SID_SET_DEFAULT:
420         {
421             // 1. Selektion merken (kriegt die eselige EditEngine nicht selbst
422             //    auf die Reihe!)
423             // 2. Update auf False (sonst flackert's noch staerker
424             // an allen selektierten Absaetzen:
425             //  a. deren Vorlage nochmal setzen, um absatzweite harte Attribute
426             //     zu entfernen
427             //  b. harte Zeichenattribute loeschen
428             // 3. Update auf True und Selektion wieder setzen
429             /*
430             ESelection aEsel= pOutlinerView->GetSelection();
431             Outliner* pOutl = pOutlinerView->GetOutliner();
432             pOutl->SetUpdateMode(sal_False);
433             List* pSelectedParas = pOutlinerView->CreateSelectionList();
434             Paragraph* pPara = (Paragraph*)pSelectedParas->First();
435             while (pPara)
436             {
437                 sal_uLong nParaPos = pOutl->GetAbsPos(pPara);
438                 String aName;
439                 SfxStyleFamily aFamily;
440                 pOutl->GetStyleSheet(nParaPos, aName, aFamily);
441                 pOutl->SetStyleSheet(nParaPos, aName, aFamily);
442                 pOutl->QuickRemoveCharAttribs(nParaPos);
443                 pPara = (Paragraph*)pSelectedParas->Next();
444             }
445             delete pSelectedParas;
446             pOutl->SetUpdateMode(sal_True);
447             pOutlinerView->SetSelection(aEsel);
448             */
449             pOutlinerView->RemoveAttribs(sal_True); // sal_True = auch Absatzattribute
450             Cancel();
451             rReq.Done();
452         }
453         break;
454 
455         case SID_SUMMARY_PAGE:
456         {
457             pOlView->SetSelectedPages();
458             SetCurrentFunction( FuSummaryPage::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
459             pOlView->GetOutliner()->Clear();
460             pOlView->FillOutliner();
461             pOlView->GetActualPage();
462             Cancel();
463         }
464         break;
465 
466         case SID_EXPAND_PAGE:
467         {
468             pOlView->SetSelectedPages();
469             SetCurrentFunction( FuExpandPage::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
470             pOlView->GetOutliner()->Clear();
471             pOlView->FillOutliner();
472             pOlView->GetActualPage();
473             Cancel();
474         }
475         break;
476 
477         case SID_INSERT_FLD_DATE_FIX:
478         case SID_INSERT_FLD_DATE_VAR:
479         case SID_INSERT_FLD_TIME_FIX:
480         case SID_INSERT_FLD_TIME_VAR:
481         case SID_INSERT_FLD_AUTHOR:
482         case SID_INSERT_FLD_PAGE:
483         case SID_INSERT_FLD_PAGES:
484         case SID_INSERT_FLD_FILE:
485         {
486             SvxFieldItem* pFieldItem = 0;
487 
488             switch( nSId )
489             {
490                 case SID_INSERT_FLD_DATE_FIX:
491                     pFieldItem = new SvxFieldItem(
492                         SvxDateField( Date(), SVXDATETYPE_FIX ), EE_FEATURE_FIELD );
493                 break;
494 
495                 case SID_INSERT_FLD_DATE_VAR:
496                     pFieldItem = new SvxFieldItem( SvxDateField(), EE_FEATURE_FIELD );
497                 break;
498 
499                 case SID_INSERT_FLD_TIME_FIX:
500                     pFieldItem = new SvxFieldItem(
501                         SvxExtTimeField( Time(), SVXTIMETYPE_FIX ), EE_FEATURE_FIELD );
502                 break;
503 
504                 case SID_INSERT_FLD_TIME_VAR:
505                     pFieldItem = new SvxFieldItem( SvxExtTimeField(), EE_FEATURE_FIELD );
506                 break;
507 
508                 case SID_INSERT_FLD_AUTHOR:
509                 {
510                     SvtUserOptions aUserOptions;
511                     pFieldItem = new SvxFieldItem(
512                             SvxAuthorField(
513                                 aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID() )
514                                 , EE_FEATURE_FIELD );
515                 }
516                 break;
517 
518                 case SID_INSERT_FLD_PAGE:
519                     pFieldItem = new SvxFieldItem( SvxPageField(), EE_FEATURE_FIELD );
520                 break;
521 
522                 case SID_INSERT_FLD_PAGES:
523                     pFieldItem = new SvxFieldItem( SvxPagesField(), EE_FEATURE_FIELD );
524                 break;
525 
526                 case SID_INSERT_FLD_FILE:
527                 {
528                     String aName;
529                     if( GetDocSh()->HasName() )
530                         aName = GetDocSh()->GetMedium()->GetName();
531                     //else
532                     //  aName = GetDocSh()->GetName();
533                     pFieldItem = new SvxFieldItem( SvxExtFileField( aName ), EE_FEATURE_FIELD );
534                 }
535                 break;
536             }
537 
538             const SvxFieldItem* pOldFldItem = pOutlinerView->GetFieldAtSelection();
539 
540             if( pOldFldItem && ( pOldFldItem->GetField()->ISA( SvxURLField ) ||
541                                 pOldFldItem->GetField()->ISA( SvxDateField ) ||
542                                 pOldFldItem->GetField()->ISA( SvxTimeField ) ||
543                                 pOldFldItem->GetField()->ISA( SvxExtTimeField ) ||
544                                 pOldFldItem->GetField()->ISA( SvxExtFileField ) ||
545                                 pOldFldItem->GetField()->ISA( SvxAuthorField ) ||
546                                 pOldFldItem->GetField()->ISA( SvxPageField ) ||
547                                 pOldFldItem->GetField()->ISA( SvxPagesField )) )
548             {
549                 // Feld selektieren, so dass es beim Insert geloescht wird
550                 ESelection aSel = pOutlinerView->GetSelection();
551                 if( aSel.nStartPos == aSel.nEndPos )
552                     aSel.nEndPos++;
553                 pOutlinerView->SetSelection( aSel );
554             }
555 
556             if( pFieldItem )
557                 pOutlinerView->InsertField( *pFieldItem );
558 
559             delete pFieldItem;
560 
561             Cancel();
562             rReq.Ignore ();
563         }
564         break;
565 
566         case SID_MODIFY_FIELD:
567         {
568             const SvxFieldItem* pFldItem = pOutlinerView->GetFieldAtSelection();
569 
570             if( pFldItem && (pFldItem->GetField()->ISA( SvxDateField ) ||
571                                 pFldItem->GetField()->ISA( SvxAuthorField ) ||
572                                 pFldItem->GetField()->ISA( SvxExtFileField ) ||
573                                 pFldItem->GetField()->ISA( SvxExtTimeField ) ) )
574             {
575                 // Dialog...
576                 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
577                 AbstractSdModifyFieldDlg* pDlg = pFact ? pFact->CreateSdModifyFieldDlg(GetActiveWindow(), pFldItem->GetField(), pOutlinerView->GetAttribs() ) : 0;
578                 if( pDlg && (pDlg->Execute() == RET_OK) )
579                 {
580                     SvxFieldData* pField = pDlg->GetField();
581                     if( pField )
582                     {
583                         SvxFieldItem aFieldItem( *pField, EE_FEATURE_FIELD );
584                         //pOLV->DeleteSelected(); <-- fehlt leider !
585                         // Feld selektieren, so dass es beim Insert geloescht wird
586                         ESelection aSel = pOutlinerView->GetSelection();
587                         sal_Bool bSel = sal_True;
588                         if( aSel.nStartPos == aSel.nEndPos )
589                         {
590                             bSel = sal_False;
591                             aSel.nEndPos++;
592                         }
593                         pOutlinerView->SetSelection( aSel );
594 
595                         pOutlinerView->InsertField( aFieldItem );
596 
597                         // Selektion wird wieder in den Ursprungszustand gebracht
598                         if( !bSel )
599                             aSel.nEndPos--;
600                         pOutlinerView->SetSelection( aSel );
601 
602                         delete pField;
603                     }
604 
605                     SfxItemSet aSet( pDlg->GetItemSet() );
606                     if( aSet.Count() )
607                     {
608                         pOutlinerView->SetAttribs( aSet );
609 
610                         ::Outliner* pOutliner = pOutlinerView->GetOutliner();
611                         if( pOutliner )
612                             pOutliner->UpdateFields();
613                     }
614                 }
615                 delete pDlg;
616             }
617 
618             Cancel();
619             rReq.Ignore ();
620         }
621         break;
622     }
623 
624     if(HasCurrentFunction())
625         GetCurrentFunction()->Activate();
626 
627     Invalidate( SID_OUTLINE_COLLAPSE_ALL );
628     Invalidate( SID_OUTLINE_COLLAPSE );
629     Invalidate( SID_OUTLINE_EXPAND_ALL );
630     Invalidate( SID_OUTLINE_EXPAND );
631 
632     SfxBindings& rBindings = GetViewFrame()->GetBindings();
633     rBindings.Invalidate( SID_OUTLINE_LEFT );
634     rBindings.Invalidate( SID_OUTLINE_RIGHT );
635     rBindings.Invalidate( SID_OUTLINE_UP );
636     rBindings.Invalidate( SID_OUTLINE_DOWN );
637 
638     Invalidate( SID_OUTLINE_FORMAT );
639     Invalidate( SID_COLORVIEW );
640     Invalidate(SID_CUT);
641     Invalidate(SID_COPY);
642     Invalidate(SID_PASTE);
643 }
644 
645 
646 } // end of namespace sd
647