1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_SD_INC_SDPAGE_HXX
21 #define INCLUDED_SD_INC_SDPAGE_HXX
22 
23 #include <com/sun/star/drawing/XDrawPage.hpp>
24 #include <com/sun/star/presentation/FadeEffect.hpp>
25 #include <com/sun/star/office/XAnnotation.hpp>
26 
27 #include <memory>
28 #include <string_view>
29 #include <vector>
30 #include <editeng/flditem.hxx>
31 #include <svx/svdobj.hxx>
32 #include <svx/fmpage.hxx>
33 #include <xmloff/autolayout.hxx>
34 #include "diadef.h"
35 #include "pres.hxx"
36 #include "shapelist.hxx"
37 #include "misc/scopelock.hxx"
38 #include "sddllapi.h"
39 
40 namespace com::sun::star::animations {
41     class XAnimationNode;
42 }
43 
44 class SfxStyleSheet;
45 class SdDrawDocument;
46 class SdrTextObj;
47 class SdPageLink;
48 class SfxItemSet;
49 class Paragraph;
50 class Outliner;
51 class SdStyleSheet;
52 class Graphic;
53 
54 namespace sd
55 {
56     class MainSequence;
57 }
58 
59 namespace sd {
60 
61     struct SD_DLLPUBLIC HeaderFooterSettings
62     {
63         bool mbHeaderVisible;
64         OUString maHeaderText;
65 
66         bool mbFooterVisible;
67         OUString maFooterText;
68 
69         bool mbSlideNumberVisible;
70 
71         bool mbDateTimeVisible;
72         bool mbDateTimeIsFixed;
73         OUString maDateTimeText;
74         SvxDateFormat meDateFormat;
75         SvxTimeFormat meTimeFormat;
76 
77         HeaderFooterSettings();
78 
79         bool operator==( const HeaderFooterSettings& rSettings ) const;
80     };
81 
82     typedef std::vector< css::uno::Reference< css::office::XAnnotation > > AnnotationVector;
83 }
84 
85 namespace sd {
86     class UndoAnimation;
87     class UndoTransition;
88     class UndoGeoObject;
89     class UndoAttrObject;
90 }
91 
92 class SD_DLLPUBLIC SdPage final : public FmFormPage, public SdrObjUserCall
93 {
94     SdPage& operator=(const SdPage&) = delete;
95     SdPage(const SdPage&) = delete;
96 
97 friend class SdGenericDrawPage;
98 friend class SdDrawPage;
99 friend class sd::UndoAnimation;
100 friend class sd::UndoTransition;
101 friend class ModifyPageUndoAction;
102 friend class sd::UndoGeoObject;
103 friend class sd::UndoAttrObject;
104 
105     PageKind    mePageKind;               ///< page type
106     AutoLayout  meAutoLayout;             ///< AutoLayout
107     sd::ShapeList maPresentationShapeList;///< presentation objects
108     sd::ScopeLock maLockAutoLayoutArrangement;
109     bool    mbSelected;               ///< selection identifier
110     PresChange  mePresChange;             ///< manual / automatic / semi automatic
111     double      mfTime;                   ///< Display time in seconds
112     bool    mbSoundOn;                ///< with / without sound.
113     bool    mbExcluded;               ///< will (not) be displayed during show.
114     OUString    maLayoutName;             ///< Name of the layout
115     OUString    maSoundFile;              ///< Path to sound file (MS-DOS notation).
116     bool        mbLoopSound;
117     bool        mbStopSound;
118     OUString    maCreatedPageName;        ///< generated page name by GetPageName.
119     OUString    maFileName;               ///< file name.
120     OUString    maBookmarkName;           ///< Bookmark name.
121     bool    mbScaleObjects;           ///< Objects should be scaled
122     rtl_TextEncoding meCharSet;           ///< Text encoding
123     sal_uInt16  mnPaperBin;               ///< PaperBin
124     SdPageLink* mpPageLink;               ///< Page link (at left sides only)
125 
126     sd::AnnotationVector    maAnnotations;
127 
128     /** holds the smil animation sequences for this page */
129     css::uno::Reference< css::animations::XAnimationNode > mxAnimationNode;
130 
131     /** a helper class to manipulate effects inside the main sequence */
132     std::shared_ptr< sd::MainSequence > mpMainSequence;
133 
134     virtual css::uno::Reference< css::uno::XInterface > createUnoPage() override;
135 
136     std::unique_ptr<SfxItemSet> mpItems;
137 
138     SfxItemSet* getOrCreateItems();
139 
140     sd::HeaderFooterSettings    maHeaderFooterSettings;
141 
142     // new transition settings
143     sal_Int16 mnTransitionType;
144     sal_Int16 mnTransitionSubtype;
145     bool mbTransitionDirection;
146     sal_Int32 mnTransitionFadeColor;
147     double mfTransitionDuration;
148 
149     void lateInit(const SdPage& rSrcPage);
150 
151 public:
152 
153     SdPage(SdDrawDocument& rNewDoc, bool bMasterPage);
154     virtual ~SdPage() override;
155 
156     virtual rtl::Reference<SdrPage> CloneSdrPage(SdrModel& rTargetModel) const override;
157 
158     virtual void    SetSize(const Size& aSize) override;
159     virtual void    SetBorder(sal_Int32 nLft, sal_Int32 nUpp, sal_Int32 nRgt, sal_Int32 Lwr) override;
160     virtual void    SetLeftBorder(sal_Int32 nBorder) override;
161     virtual void    SetRightBorder(sal_Int32 nBorder) override;
162     virtual void    SetUpperBorder(sal_Int32 nBorder) override;
163     virtual void    SetLowerBorder(sal_Int32 nBorder) override;
164     virtual bool    IsReadOnly() const override;
165 
GetPresentationShapeList()166     sd::ShapeList&  GetPresentationShapeList() { return maPresentationShapeList; }
167 
168     void EnsureMasterPageDefaultBackground();
169     SdrObject*      CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::tools::Rectangle& rRect);
170     SdrObject*      CreateDefaultPresObj(PresObjKind eObjKind);
171     void            DestroyDefaultPresObj(PresObjKind eObjKind);
172     SdrObject*      GetPresObj(PresObjKind eObjKind, int nIndex = 1, bool bFuzzySearch = false );
173     PresObjKind     GetPresObjKind(SdrObject* pObj) const;
174     OUString        GetPresObjText(PresObjKind eObjKind) const;
175     SfxStyleSheet* GetStyleSheetForMasterPageBackground() const;
176     SfxStyleSheet*  GetStyleSheetForPresObj(PresObjKind eObjKind) const;
177     sal_Int64       GetHashCode() const;
178     bool            RestoreDefaultText( SdrObject* pObj );
179 
180     /** @return true if the given SdrObject is inside the presentation object list */
181     bool            IsPresObj(const SdrObject* pObj);
182 
183     /** removes the given SdrObject from the presentation object list */
184     void            RemovePresObj(const SdrObject* pObj);
185 
186     /** inserts the given SdrObject into the presentation object list */
187     void            InsertPresObj(SdrObject* pObj, PresObjKind eKind );
188 
189     void            SetAutoLayout(AutoLayout eLayout, bool bInit=false, bool bCreate=false);
GetAutoLayout() const190     AutoLayout      GetAutoLayout() const { return meAutoLayout; }
191     void            CreateTitleAndLayout(bool bInit=false, bool bCreate=false);
192     SdrObject*      InsertAutoLayoutShape(SdrObject* pObj, PresObjKind eObjKind, bool bVertical, const ::tools::Rectangle& rRect, bool bInit);
193 
194     virtual void       NbcInsertObject(SdrObject* pObj, size_t nPos=SAL_MAX_SIZE) override;
195     virtual SdrObject* NbcRemoveObject(size_t nObjNum) override;
196     virtual SdrObject* RemoveObject(size_t nObjNum) override;
197 
198     /** Also override ReplaceObject methods to realize when
199     objects are removed with this mechanism instead of RemoveObject*/
200     virtual SdrObject* ReplaceObject(SdrObject* pNewObj, size_t nObjNum) override;
201 
202     void        SetObjText(SdrTextObj* pObj, SdrOutliner* pOutliner, PresObjKind eObjKind, std::u16string_view rStr );
203 
SetPageKind(PageKind ePgType)204     void        SetPageKind(PageKind ePgType)        { mePageKind = ePgType; }
GetPageKind() const205     PageKind    GetPageKind() const                  { return mePageKind; }
206 
SetSelected(bool bSel)207     void        SetSelected(bool bSel)               { mbSelected = bSel; }
IsSelected() const208     bool        IsSelected() const                   { return mbSelected; }
209 
210     void        SetFadeEffect(css::presentation::FadeEffect eNewEffect);
211     css::presentation::FadeEffect  GetFadeEffect() const;
212 
SetPresChange(PresChange eChange)213     void        SetPresChange(PresChange eChange)    { mePresChange = eChange; }
GetPresChange() const214     PresChange  GetPresChange() const                { return mePresChange; }
215 
SetTime(double fNewTime)216     void        SetTime(double fNewTime)             { mfTime = fNewTime; }
GetTime() const217     double      GetTime() const                      { return mfTime; }
218 
SetSound(bool bNewSoundOn)219     void        SetSound(bool bNewSoundOn)           { mbSoundOn = bNewSoundOn; }
IsSoundOn() const220     bool        IsSoundOn() const                    { return mbSoundOn; }
221 
SetExcluded(bool bNewExcluded)222     void        SetExcluded(bool bNewExcluded)      { mbExcluded = bNewExcluded; }
IsExcluded() const223     bool        IsExcluded() const                  { return mbExcluded; }
224 
IsScaleObjects() const225     bool        IsScaleObjects() const              { return mbScaleObjects; }
226 
SetSoundFile(const OUString & rStr)227     void        SetSoundFile(const OUString& rStr)    { maSoundFile = rStr; }
GetSoundFile() const228     const OUString& GetSoundFile() const                { return maSoundFile; }
229 
SetLoopSound(bool bLoopSound)230     void        SetLoopSound( bool bLoopSound ) { mbLoopSound = bLoopSound; }
IsLoopSound() const231     bool        IsLoopSound() const                 { return mbLoopSound; }
232 
SetStopSound(bool bStopSound)233     void        SetStopSound( bool bStopSound ) { mbStopSound = bStopSound; }
IsStopSound() const234     bool        IsStopSound() const             { return mbStopSound; }
235 
getTransitionType() const236     sal_Int16   getTransitionType() const { return mnTransitionType;}
237     void        setTransitionType( sal_Int16 nTransitionType );
238 
getTransitionSubtype() const239     sal_Int16   getTransitionSubtype() const { return mnTransitionSubtype;}
240     void        setTransitionSubtype( sal_Int16 nTransitionSubtype );
241 
getTransitionDirection() const242     bool    getTransitionDirection() const { return mbTransitionDirection;}
243     void        setTransitionDirection( bool bTransitionbDirection );
244 
getTransitionFadeColor() const245     sal_Int32   getTransitionFadeColor() const { return mnTransitionFadeColor;}
246     void        setTransitionFadeColor( sal_Int32 nTransitionFadeColor );
247 
getTransitionDuration() const248     double      getTransitionDuration() const { return mfTransitionDuration;}
249     void        setTransitionDuration( double fTransitionDuration );
250 
251     virtual void Changed(const SdrObject& rObj, SdrUserCallType eType,
252                          const ::tools::Rectangle& rOldBoundRect) override;
253 
254     void             SetLayoutName(const OUString& aName);
GetLayoutName() const255     virtual OUString GetLayoutName() const override       { return maLayoutName; }
256 
SetFileName(const OUString & aName)257     void            SetFileName(const OUString& aName) { maFileName = aName; }
GetFileName() const258     const OUString& GetFileName() const       { return maFileName; }
SetBookmarkName(const OUString & aName)259     void            SetBookmarkName(const OUString& aName) { maBookmarkName = aName; }
GetBookmarkName() const260     const OUString& GetBookmarkName() const       { return maBookmarkName; }
261 
262     void            ConnectLink();
263     void            DisconnectLink();
264 
265     void            ScaleObjects(const Size& rNewPageSize, const ::tools::Rectangle& rNewBorderRect,
266                          bool bScaleAllObj);
267 
268     const OUString& GetName() const;
GetRealName() const269     OUString const & GetRealName() const { return FmFormPage::GetName(); };
270 
271     void            SetPresentationLayout(std::u16string_view rLayoutName,
272                                   bool bReplaceStyleSheets = true,
273                                   bool bSetMasterPage = true,
274                                   bool bReverseOrder = false);
275     void            EndListenOutlineText();
276 
SetPaperBin(sal_uInt16 nBin)277     void    SetPaperBin(sal_uInt16 nBin) { mnPaperBin = nBin; }
GetPaperBin() const278     sal_uInt16  GetPaperBin() const { return mnPaperBin; }
279     virtual void        SetOrientation(Orientation eOrient) override;
280     virtual Orientation GetOrientation() const override;
281 
282     virtual SfxStyleSheet* GetTextStyleSheetForObject( SdrObject* pObj ) const override;
283 
284     bool setAlienAttributes( const css::uno::Any& rAttributes );
285     void getAlienAttributes( css::uno::Any& rAttributes );
286 
287     /** @return the main animation node
288 
289         @throws css::uno::RuntimeException
290     */
291     css::uno::Reference< css::animations::XAnimationNode > const & getAnimationNode();
292 
293     /** sets the main animation node
294 
295         @throws css::uno::RuntimeException
296     */
297     void setAnimationNode( css::uno::Reference< css::animations::XAnimationNode > const & xNode );
298 
299     /// @return a helper class to manipulate effects inside the main sequence
300     std::shared_ptr< sd::MainSequence > const & getMainSequence();
301 
302     /** quick check if this slide has an animation node.
303         This can be used to have a cost free check if there are no animations ad this slide.
304         If it returns true this does not mean that there are animations available.
305     */
306     bool hasAnimationNode() const;
307 
308     /// @return the SdPage implementation for the given XDrawPage or 0 if not available
309     static SdPage* getImplementation( const css::uno::Reference< css::drawing::XDrawPage >& xPage );
310 
311     /** removes all custom animations for the given shape */
312     void removeAnimations( const SdrObject* pObj );
313 
314     /** Notify that the object has been renamed and the animation effects has to update. */
315     void notifyObjectRenamed(const SdrObject* pObj);
316 
317     /** Set the name of the page and broadcast a model change.
318     */
319     void SetName (const OUString& rName);
320 
321     const sd::HeaderFooterSettings& getHeaderFooterSettings() const;
322     void setHeaderFooterSettings( const sd::HeaderFooterSettings& rNewSettings );
323 
324     /**
325         @return true if the object from the ViewObjectContact should
326         be visible on this page while rendering.
327 
328         bEdit selects if visibility test is for an editing view or a final render,
329         like printing.
330     */
331     virtual bool checkVisibility(
332         const sdr::contact::ViewObjectContact& rOriginal,
333         const sdr::contact::DisplayInfo& rDisplayInfo,
334         bool bEdit ) override;
335 
336     /** callback from the sd::View when a new paragraph for one object on this page is created */
337     void onParagraphInserted( ::Outliner* pOutliner, Paragraph const * pPara, SdrObject* pObj );
338 
339     /** callback from the sd::View when a paragraph from one object on this page is removed */
340     void onParagraphRemoving( ::Outliner* pOutliner, Paragraph const * pPara, SdrObject* pObj );
341 
342     /** callback from the sd::View when an object just left text edit mode */
343     void onEndTextEdit( SdrObject* pObj );
344 
345     /** @return the presentation style with the given helpid from this masterpage or this
346         slides masterpage */
347     SdStyleSheet* getPresentationStyle( sal_uInt32 nHelpId ) const;
348 
349     /** removes all empty presentation objects from this slide */
350     void RemoveEmptyPresentationObjects();
351 
352     ::tools::Rectangle   GetTitleRect() const;
353     ::tools::Rectangle   GetLayoutRect() const;
354 
355     static void CalculateHandoutAreas( SdDrawDocument& rModel, AutoLayout eLayout, bool bHorizontal, std::vector< ::tools::Rectangle >& rAreas );
356 
357     /** Set the "precious" flag to the given value.
358     */
359     void SetPrecious (const bool bIsPrecious);
360 
361     /** The "precious" flag is used for master pages to prevent some unused
362         master pages from being deleted automatically.  For pages
363         other than master pages this flag can be ignored.
364         @return
365             When this method returns <TRUE/> for a master page then this
366             master page should not be deleted automatically.
367     */
IsPrecious() const368     bool IsPrecious() const { return mbIsPrecious; }
369 
370     void createAnnotation( css::uno::Reference< css::office::XAnnotation >& xAnnotation );
371     void addAnnotation( const css::uno::Reference< css::office::XAnnotation >& xAnnotation, int nIndex );
372     void removeAnnotation( const css::uno::Reference< css::office::XAnnotation >& xAnnotation );
getAnnotations() const373     const sd::AnnotationVector& getAnnotations() const { return maAnnotations; }
374     bool Equals(const SdPage&) const;
375     virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
getPageId() const376     sal_uInt16 getPageId() const { return mnPageId; }
377 
378     /**
379      Returns graphics objects from the page that can be prefetched before it's painted.
380      The pointers are temporary and should not be kept.
381     */
382     void getGraphicsForPrefetch(std::vector<Graphic*>& graphics) const;
383 
384     static sal_uInt16 mnLastPageId;
385 
386 private:
387     bool mbIsPrecious;
388 
389     // page id of this page
390     sal_uInt16 mnPageId;
391 
392     /** clone the animations from this and set them to rTargetPage
393      *  TTTT: Order is strange, should be the other way around by
394      *  convention/convenience and makes usage a little dangerous...
395     */
396     void cloneAnimations( SdPage& rTargetPage ) const;
397 
398     /** called before a shape is removed or replaced from this slide */
399     void onRemoveObject( SdrObject* pObject );
400 };
401 
402 #endif // INCLUDED_SD_INC_SDPAGE_HXX
403 
404 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
405