merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / view / outlnvs2.cxx
blobf807a67b07ab7420852006551fd78b80f437cb0a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: outlnvs2.cxx,v $
10 * $Revision: 1.31.36.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "OutlineViewShell.hxx"
36 #include <com/sun/star/presentation/XPresentation2.hpp>
38 #include "app.hrc"
39 #include <svx/hlnkitem.hxx>
40 #include <sfx2/docfile.hxx>
41 #include <sfx2/dispatch.hxx>
42 #include <sfx2/request.hxx>
43 #include <svtools/eitem.hxx>
44 #ifndef _ZOOMITEM_HXX //autogen
45 #include <svx/zoomitem.hxx>
46 #endif
47 #include <vcl/msgbox.hxx>
48 #include <svx/eeitem.hxx>
49 #include <svx/flditem.hxx>
50 #include <svx/editstat.hxx>
51 #include "optsitem.hxx"
52 #include <svtools/useroptions.hxx>
54 #include <sfx2/viewfrm.hxx>
55 #include "Outliner.hxx"
56 #include "Window.hxx"
57 #include "OutlineViewShell.hxx"
58 #include "fubullet.hxx"
59 #include "fuolbull.hxx"
60 #include "FrameView.hxx"
61 #include "fuzoom.hxx"
62 #include "fuscale.hxx"
63 #include "fuchar.hxx"
64 #include "fuinsfil.hxx"
65 #include "fuprobjs.hxx"
66 #include "futhes.hxx"
67 #include "futempl.hxx"
68 #include "fusldlg.hxx"
69 #include "zoomlist.hxx"
70 #include "fuexpand.hxx"
71 #include "fusumry.hxx"
72 #include "fucushow.hxx"
73 #include "drawdoc.hxx"
74 #include "sdattr.hxx"
75 #include "ViewShellBase.hxx"
76 #include "sdabstdlg.hxx"
77 #include "framework/FrameworkHelper.hxx"
78 #include "DrawViewShell.hxx"
80 using namespace ::com::sun::star::uno;
81 using namespace ::com::sun::star::presentation;
83 namespace sd {
86 /************************************************************************/
88 /*************************************************************************
90 |* SfxRequests fuer temporaere Funktionen
92 \************************************************************************/
94 void OutlineViewShell::FuTemporary(SfxRequest &rReq)
96 DeactivateCurrentFunction();
98 OutlinerView* pOutlinerView = pOlView->GetViewByWindow( GetActiveWindow() );
99 USHORT nSId = rReq.GetSlot();
101 switch( nSId )
103 case SID_ATTR_ZOOM:
105 const SfxItemSet* pArgs = rReq.GetArgs();
107 if ( pArgs )
109 SvxZoomType eZT = ( ( const SvxZoomItem& ) pArgs->
110 Get( SID_ATTR_ZOOM ) ).GetType();
111 switch( eZT )
113 case SVX_ZOOM_PERCENT:
114 SetZoom( (long) ( ( const SvxZoomItem& ) pArgs->
115 Get( SID_ATTR_ZOOM ) ).GetValue() );
116 Invalidate( SID_ATTR_ZOOM );
117 Invalidate( SID_ATTR_ZOOMSLIDER );
118 break;
119 default:
120 break;
122 rReq.Done();
124 else
126 // hier den Zoom-Dialog oeffnen
127 SetCurrentFunction( FuScale::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
129 Cancel();
131 break;
133 case SID_ATTR_ZOOMSLIDER:
135 const SfxItemSet* pArgs = rReq.GetArgs();
137 if (pArgs && pArgs->Count () == 1 )
139 SFX_REQUEST_ARG (rReq, pScale, SfxUInt16Item, SID_ATTR_ZOOMSLIDER, FALSE);
140 if (CHECK_RANGE (5, pScale->GetValue (), 3000))
142 SetZoom (pScale->GetValue ());
144 SfxBindings& rBindings = GetViewFrame()->GetBindings();
145 rBindings.Invalidate( SID_ATTR_ZOOM );
146 rBindings.Invalidate( SID_ZOOM_IN );
147 rBindings.Invalidate( SID_ZOOM_OUT );
148 rBindings.Invalidate( SID_ATTR_ZOOMSLIDER );
153 Cancel();
154 rReq.Done ();
155 break;
158 case SID_ZOOM_OUT:
160 SetCurrentFunction( FuZoom::Create(this, GetActiveWindow(), pOlView, GetDoc(), rReq) );
161 // Beendet sich selbst, kein Cancel() notwendig!
162 rReq.Done();
164 break;
166 case SID_SIZE_REAL:
168 SetZoom( 100 );
169 Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( Rectangle( Point(0,0),
170 GetActiveWindow()->GetOutputSizePixel()) );
171 mpZoomList->InsertZoomRect(aVisAreaWin);
172 Invalidate( SID_ATTR_ZOOM );
173 Invalidate( SID_ATTR_ZOOMSLIDER );
174 Cancel();
175 rReq.Done();
177 break;
179 case SID_ZOOM_IN:
181 SetZoom( Max( (long) ( GetActiveWindow()->GetZoom() / 2 ), (long) GetActiveWindow()->GetMinZoom() ) );
182 Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( Rectangle( Point(0,0),
183 GetActiveWindow()->GetOutputSizePixel()) );
184 mpZoomList->InsertZoomRect(aVisAreaWin);
185 Invalidate( SID_ATTR_ZOOM );
186 Invalidate( SID_ZOOM_OUT);
187 Invalidate( SID_ZOOM_IN );
188 Invalidate( SID_ATTR_ZOOMSLIDER );
189 Cancel();
190 rReq.Done();
192 break;
194 case SID_OUTLINE_COLLAPSE_ALL:
196 pOutlinerView->CollapseAll();
197 Cancel();
198 rReq.Done();
200 break;
202 case SID_OUTLINE_COLLAPSE:
204 pOutlinerView->Collapse();
205 Cancel();
206 rReq.Done();
208 break;
210 case SID_OUTLINE_EXPAND_ALL:
212 pOutlinerView->ExpandAll();
213 Cancel();
214 rReq.Done();
216 break;
218 case SID_OUTLINE_EXPAND:
220 pOutlinerView->Expand();
221 Cancel();
222 rReq.Done();
224 break;
226 case SID_OUTLINE_FORMAT:
228 ::Outliner* pOutl = pOutlinerView->GetOutliner();
229 pOutl->SetFlatMode( !pOutl->IsFlatMode() );
230 Invalidate( SID_COLORVIEW );
231 Cancel();
232 rReq.Done();
234 break;
236 case SID_SELECTALL:
238 ::Outliner* pOutl = pOlView->GetOutliner();
239 ULONG nParaCount = pOutl->GetParagraphCount();
240 if (nParaCount > 0)
242 pOutlinerView->SelectRange( 0, (USHORT) nParaCount );
244 Cancel();
246 break;
248 case SID_PRESENTATION:
249 case SID_REHEARSE_TIMINGS:
251 pOlView->PrepareClose();
253 Reference< XPresentation2 > xPresentation( GetDoc()->getPresentation() );
254 if( xPresentation.is() )
256 if( ( SID_REHEARSE_TIMINGS != rReq.GetSlot() ) )
257 xPresentation->start();
258 else
259 xPresentation->rehearseTimings();
261 rReq.Done();
263 break;
265 case SID_COLORVIEW:
267 ::Outliner* pOutl = pOutlinerView->GetOutliner();
268 ULONG nCntrl = pOutl->GetControlWord();
270 if ( !(nCntrl & EE_CNTRL_NOCOLORS) )
272 // Farbansicht ist eingeschaltet: ausschalten
273 pOutl->SetControlWord(nCntrl | EE_CNTRL_NOCOLORS);
275 else
277 // Farbansicht ist ausgeschaltet: einschalten
278 pOutl->SetControlWord(nCntrl & ~EE_CNTRL_NOCOLORS);
281 InvalidateWindows();
282 Invalidate( SID_COLORVIEW );
283 Cancel();
284 rReq.Done();
286 break;
288 case SID_STYLE_EDIT:
289 case SID_STYLE_UPDATE_BY_EXAMPLE:
291 if( rReq.GetArgs() )
293 SetCurrentFunction( FuTemplate::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
294 Cancel();
297 rReq.Ignore ();
299 break;
301 case SID_PRESENTATION_DLG:
303 SetCurrentFunction( FuSlideShowDlg::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
304 Cancel();
306 break;
308 case SID_CUSTOMSHOW_DLG:
310 SetCurrentFunction( FuCustomShowDlg::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
311 Cancel();
313 break;
316 if(HasCurrentFunction())
317 GetCurrentFunction()->Activate();
319 Invalidate( SID_OUTLINE_COLLAPSE_ALL );
320 Invalidate( SID_OUTLINE_COLLAPSE );
321 Invalidate( SID_OUTLINE_EXPAND_ALL );
322 Invalidate( SID_OUTLINE_EXPAND );
324 SfxBindings& rBindings = GetViewFrame()->GetBindings();
325 rBindings.Invalidate( SID_OUTLINE_LEFT );
326 rBindings.Invalidate( SID_OUTLINE_RIGHT );
327 rBindings.Invalidate( SID_OUTLINE_UP );
328 rBindings.Invalidate( SID_OUTLINE_DOWN );
330 Invalidate( SID_OUTLINE_FORMAT );
331 Invalidate( SID_COLORVIEW );
332 Invalidate(SID_CUT);
333 Invalidate(SID_COPY);
334 Invalidate(SID_PASTE);
337 void OutlineViewShell::FuTemporaryModify(SfxRequest &rReq)
339 OutlineViewModelChangeGuard aGuard( *pOlView );
341 DeactivateCurrentFunction();
343 OutlinerView* pOutlinerView = pOlView->GetViewByWindow( GetActiveWindow() );
344 USHORT nSId = rReq.GetSlot();
346 switch( nSId )
348 case SID_HYPERLINK_SETLINK:
350 const SfxItemSet* pReqArgs = rReq.GetArgs();
352 if (pReqArgs)
354 SvxHyperlinkItem* pHLItem =
355 (SvxHyperlinkItem*) &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.nStartPos <= aSel.nEndPos )
363 aSel.nEndPos = aSel.nStartPos + 1;
364 else
365 aSel.nStartPos = aSel.nEndPos + 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 SID_INSERT_RLM :
378 case SID_INSERT_LRM :
379 case SID_INSERT_ZWNBSP :
380 case SID_INSERT_ZWSP:
381 case SID_CHARMAP:
383 SetCurrentFunction( FuBullet::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
384 Cancel();
386 break;
388 case SID_OUTLINE_BULLET:
390 SetCurrentFunction( FuOutlineBullet::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
391 Cancel();
393 break;
395 case SID_THESAURUS:
397 SetCurrentFunction( FuThesaurus::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
398 Cancel();
399 rReq.Ignore ();
401 break;
403 case SID_CHAR_DLG:
405 SetCurrentFunction( FuChar::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
406 Cancel();
408 break;
410 case SID_INSERTFILE:
412 SetCurrentFunction( FuInsertFile::Create(this, GetActiveWindow(), pOlView, GetDoc(), rReq) );
413 Cancel();
415 break;
417 case SID_PRESENTATIONOBJECT:
419 SetCurrentFunction( FuPresentationObjects::Create(this, GetActiveWindow(), pOlView, GetDoc(), rReq) );
420 Cancel();
422 break;
424 case SID_SET_DEFAULT:
426 // 1. Selektion merken (kriegt die eselige EditEngine nicht selbst
427 // auf die Reihe!)
428 // 2. Update auf False (sonst flackert's noch staerker
429 // an allen selektierten Absaetzen:
430 // a. deren Vorlage nochmal setzen, um absatzweite harte Attribute
431 // zu entfernen
432 // b. harte Zeichenattribute loeschen
433 // 3. Update auf True und Selektion wieder setzen
435 ESelection aEsel= pOutlinerView->GetSelection();
436 Outliner* pOutl = pOutlinerView->GetOutliner();
437 pOutl->SetUpdateMode(FALSE);
438 List* pSelectedParas = pOutlinerView->CreateSelectionList();
439 Paragraph* pPara = (Paragraph*)pSelectedParas->First();
440 while (pPara)
442 ULONG nParaPos = pOutl->GetAbsPos(pPara);
443 String aName;
444 SfxStyleFamily aFamily;
445 pOutl->GetStyleSheet(nParaPos, aName, aFamily);
446 pOutl->SetStyleSheet(nParaPos, aName, aFamily);
447 pOutl->QuickRemoveCharAttribs(nParaPos);
448 pPara = (Paragraph*)pSelectedParas->Next();
450 delete pSelectedParas;
451 pOutl->SetUpdateMode(TRUE);
452 pOutlinerView->SetSelection(aEsel);
454 pOutlinerView->RemoveAttribs(TRUE); // TRUE = auch Absatzattribute
455 Cancel();
456 rReq.Done();
458 break;
460 case SID_SUMMARY_PAGE:
462 pOlView->SetSelectedPages();
463 SetCurrentFunction( FuSummaryPage::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
464 pOlView->GetOutliner()->Clear();
465 pOlView->FillOutliner();
466 pOlView->GetActualPage();
467 Cancel();
469 break;
471 case SID_EXPAND_PAGE:
473 pOlView->SetSelectedPages();
474 SetCurrentFunction( FuExpandPage::Create( this, GetActiveWindow(), pOlView, GetDoc(), rReq ) );
475 pOlView->GetOutliner()->Clear();
476 pOlView->FillOutliner();
477 pOlView->GetActualPage();
478 Cancel();
480 break;
482 case SID_INSERT_FLD_DATE_FIX:
483 case SID_INSERT_FLD_DATE_VAR:
484 case SID_INSERT_FLD_TIME_FIX:
485 case SID_INSERT_FLD_TIME_VAR:
486 case SID_INSERT_FLD_AUTHOR:
487 case SID_INSERT_FLD_PAGE:
488 case SID_INSERT_FLD_PAGES:
489 case SID_INSERT_FLD_FILE:
491 SvxFieldItem* pFieldItem = 0;
493 switch( nSId )
495 case SID_INSERT_FLD_DATE_FIX:
496 pFieldItem = new SvxFieldItem(
497 SvxDateField( Date(), SVXDATETYPE_FIX ), EE_FEATURE_FIELD );
498 break;
500 case SID_INSERT_FLD_DATE_VAR:
501 pFieldItem = new SvxFieldItem( SvxDateField(), EE_FEATURE_FIELD );
502 break;
504 case SID_INSERT_FLD_TIME_FIX:
505 pFieldItem = new SvxFieldItem(
506 SvxExtTimeField( Time(), SVXTIMETYPE_FIX ), EE_FEATURE_FIELD );
507 break;
509 case SID_INSERT_FLD_TIME_VAR:
510 pFieldItem = new SvxFieldItem( SvxExtTimeField(), EE_FEATURE_FIELD );
511 break;
513 case SID_INSERT_FLD_AUTHOR:
515 SvtUserOptions aUserOptions;
516 pFieldItem = 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 = new SvxFieldItem( SvxPageField(), EE_FEATURE_FIELD );
525 break;
527 case SID_INSERT_FLD_PAGES:
528 pFieldItem = new SvxFieldItem( SvxPagesField(), EE_FEATURE_FIELD );
529 break;
531 case SID_INSERT_FLD_FILE:
533 String aName;
534 if( GetDocSh()->HasName() )
535 aName = GetDocSh()->GetMedium()->GetName();
536 //else
537 // aName = GetDocSh()->GetName();
538 pFieldItem = new SvxFieldItem( SvxExtFileField( aName ), EE_FEATURE_FIELD );
540 break;
543 const SvxFieldItem* pOldFldItem = pOutlinerView->GetFieldAtSelection();
545 if( pOldFldItem && ( pOldFldItem->GetField()->ISA( SvxURLField ) ||
546 pOldFldItem->GetField()->ISA( SvxDateField ) ||
547 pOldFldItem->GetField()->ISA( SvxTimeField ) ||
548 pOldFldItem->GetField()->ISA( SvxExtTimeField ) ||
549 pOldFldItem->GetField()->ISA( SvxExtFileField ) ||
550 pOldFldItem->GetField()->ISA( SvxAuthorField ) ||
551 pOldFldItem->GetField()->ISA( SvxPageField ) ||
552 pOldFldItem->GetField()->ISA( SvxPagesField )) )
554 // Feld selektieren, so dass es beim Insert geloescht wird
555 ESelection aSel = pOutlinerView->GetSelection();
556 if( aSel.nStartPos == aSel.nEndPos )
557 aSel.nEndPos++;
558 pOutlinerView->SetSelection( aSel );
561 if( pFieldItem )
562 pOutlinerView->InsertField( *pFieldItem );
564 delete pFieldItem;
566 Cancel();
567 rReq.Ignore ();
569 break;
571 case SID_MODIFY_FIELD:
573 const SvxFieldItem* pFldItem = pOutlinerView->GetFieldAtSelection();
575 if( pFldItem && (pFldItem->GetField()->ISA( SvxDateField ) ||
576 pFldItem->GetField()->ISA( SvxAuthorField ) ||
577 pFldItem->GetField()->ISA( SvxExtFileField ) ||
578 pFldItem->GetField()->ISA( SvxExtTimeField ) ) )
580 // Dialog...
581 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
582 AbstractSdModifyFieldDlg* pDlg = pFact ? pFact->CreateSdModifyFieldDlg(GetActiveWindow(), pFldItem->GetField(), pOutlinerView->GetAttribs() ) : 0;
583 if( pDlg && (pDlg->Execute() == RET_OK) )
585 SvxFieldData* pField = pDlg->GetField();
586 if( pField )
588 SvxFieldItem aFieldItem( *pField, EE_FEATURE_FIELD );
589 //pOLV->DeleteSelected(); <-- fehlt leider !
590 // Feld selektieren, so dass es beim Insert geloescht wird
591 ESelection aSel = pOutlinerView->GetSelection();
592 BOOL bSel = TRUE;
593 if( aSel.nStartPos == aSel.nEndPos )
595 bSel = FALSE;
596 aSel.nEndPos++;
598 pOutlinerView->SetSelection( aSel );
600 pOutlinerView->InsertField( aFieldItem );
602 // Selektion wird wieder in den Ursprungszustand gebracht
603 if( !bSel )
604 aSel.nEndPos--;
605 pOutlinerView->SetSelection( aSel );
607 delete pField;
610 SfxItemSet aSet( pDlg->GetItemSet() );
611 if( aSet.Count() )
613 pOutlinerView->SetAttribs( aSet );
615 ::Outliner* pOutliner = pOutlinerView->GetOutliner();
616 if( pOutliner )
617 pOutliner->UpdateFields();
620 delete pDlg;
623 Cancel();
624 rReq.Ignore ();
626 break;
629 if(HasCurrentFunction())
630 GetCurrentFunction()->Activate();
632 Invalidate( SID_OUTLINE_COLLAPSE_ALL );
633 Invalidate( SID_OUTLINE_COLLAPSE );
634 Invalidate( SID_OUTLINE_EXPAND_ALL );
635 Invalidate( SID_OUTLINE_EXPAND );
637 SfxBindings& rBindings = GetViewFrame()->GetBindings();
638 rBindings.Invalidate( SID_OUTLINE_LEFT );
639 rBindings.Invalidate( SID_OUTLINE_RIGHT );
640 rBindings.Invalidate( SID_OUTLINE_UP );
641 rBindings.Invalidate( SID_OUTLINE_DOWN );
643 Invalidate( SID_OUTLINE_FORMAT );
644 Invalidate( SID_COLORVIEW );
645 Invalidate(SID_CUT);
646 Invalidate(SID_COPY);
647 Invalidate(SID_PASTE);
651 } // end of namespace sd