xref: /core/sd/source/ui/inc/OutlineView.hxx (revision 29191947)
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 #pragma once
21 
22 #include <memory>
23 #include <vcl/image.hxx>
24 #include <vcl/vclevent.hxx>
25 #include <editeng/lrspitem.hxx>
26 #include <o3tl/deleter.hxx>
27 #include "View.hxx"
28 
29 class SdPage;
30 class SdrPage;
31 class SdrTextObj;
32 class SfxProgress;
33 struct PasteOrDropInfos;
34 class EditView;
35 
36 namespace sd::tools {
37     class EventMultiplexerEvent;
38 }
39 
40 namespace sd {
41 
42 class DrawDocShell;
43 class OutlineViewShell;
44 class OutlineViewModelChangeGuard;
45 
46 const int MAX_OUTLINERVIEWS = 4;
47 
48 /**
49  *  Common base for OutlineView and NotesPanelView that only have a single Outliner in the view.
50 |*
51 \************************************************************************/
52 class SimpleOutlinerView : public ::sd::View
53 {
54 public:
SimpleOutlinerView(SdDrawDocument & rDrawDoc,OutputDevice * pOutDev,ViewShell * pViewSh)55     SimpleOutlinerView(SdDrawDocument& rDrawDoc, OutputDevice* pOutDev, ViewShell* pViewSh)
56             : View(rDrawDoc, pOutDev, pViewSh) {}
57     virtual OutlinerView* GetViewByWindow(vcl::Window const* pWin) const = 0;
58 };
59 
60 /**
61  * Derivative of ::sd::SimpleOutlinerView for the outline mode
62 |*
63 \************************************************************************/
64 
65 class OutlineView final
66     : public SimpleOutlinerView
67 {
68     friend class OutlineViewModelChangeGuard;
69 public:
70     OutlineView (DrawDocShell& rDocSh,
71         vcl::Window* pWindow,
72         OutlineViewShell& rOutlineViewSh);
73     virtual ~OutlineView() override;
74 
75     /** This method is called by the view shell that owns the view to tell
76         the view that it can safely connect to the application.
77         This method must not be called before the view shell is on the shell
78         stack.
79     */
80     void ConnectToApplication();
81     void DisconnectFromApplication();
82 
83 
84     static SdrTextObj*     GetTitleTextObject(SdrPage const * pPage);
85     static SdrTextObj*     GetOutlineTextObject(SdrPage const * pPage);
86 
87     static SdrTextObj*     CreateTitleTextObject(SdPage* pPage);
88     static SdrTextObj*     CreateOutlineTextObject(SdPage* pPage);
89 
90     virtual void AddDeviceToPaintView(OutputDevice& rDev, vcl::Window* pWindow) override;
91     virtual void DeleteDeviceFromPaintView(OutputDevice& rDev) override;
92 
93     OutlinerView*   GetViewByWindow(vcl::Window const * pWin) const override;
GetOutliner()94     SdOutliner&     GetOutliner() { return mrOutliner; }
95 
96     Paragraph*      GetPrevTitle(const Paragraph* pPara);
97     Paragraph*      GetNextTitle(const Paragraph* pPara);
98     SdPage*         GetActualPage();
99     SdPage*         GetPageForParagraph( Paragraph* pPara );
100     Paragraph*      GetParagraphForPage( ::Outliner const & rOutl, SdPage const * pPage );
101 
102     /** selects the paragraph for the given page at the outliner view*/
103     void            SetActualPage( SdPage const * pActual );
104 
105     void Paint (const ::tools::Rectangle& rRect, ::sd::Window const * pWin);
106 
107                     // Callbacks for LINKs
108     DECL_LINK( ParagraphInsertedHdl, ::Outliner::ParagraphHdlParam, void );
109     DECL_LINK( ParagraphRemovingHdl, ::Outliner::ParagraphHdlParam, void );
110     DECL_LINK( DepthChangedHdl, ::Outliner::DepthChangeHdlParam, void );
111     DECL_LINK( StatusEventHdl, EditStatus&, void );
112     DECL_LINK( BeginMovingHdl, ::Outliner *, void );
113     DECL_LINK( EndMovingHdl, ::Outliner *, void );
114     DECL_LINK( RemovingPagesHdl, OutlinerView *, bool );
115     DECL_LINK( IndentingPagesHdl, OutlinerView *, bool );
116     DECL_LINK( BeginDropHdl, EditView*, void );
117     DECL_LINK( EndDropHdl, EditView*, void );
118     DECL_LINK( PaintingFirstLineHdl, PaintFirstLineInfo*, void );
119 
GetPaperWidth() const120     sal_uLong         GetPaperWidth() const { return mnPaperWidth;}
121 
122     void              PrepareClose();
123 
124     virtual void    GetAttributes( SfxItemSet& rTargetSet, bool bOnlyHardAttr = false ) const override;
125     virtual bool    SetAttributes(const SfxItemSet& rSet, bool bReplaceAll = false, bool bSlide = false, bool bMaster = false) override;
126 
127     void               FillOutliner();
128     void               SetLinks();
129     void               ResetLinks() const;
130 
131     SfxStyleSheet*     GetStyleSheet() const override;
132 
133     void               SetSelectedPages();
134 
135     virtual sal_Int8 AcceptDrop (
136         const AcceptDropEvent& rEvt,
137         DropTargetHelper& rTargetHelper,
138         SdrLayerID nLayer) override;
139     virtual sal_Int8 ExecuteDrop (
140         const ExecuteDropEvent& rEvt,
141         ::sd::Window* pTargetWindow,
142         sal_uInt16 nPage,
143         SdrLayerID nLayer) override;
144 
145     // Re-implement GetScriptType for this view to get correct results
146     virtual SvtScriptType GetScriptType() const override;
147 
148     /** After this method has been called with <TRUE/> following changes of
149         the current page are ignored in that the corresponding text is not
150         selected.
151         This is used to suppress unwanted side effects between selection and
152         cursor position.
153     */
154     void IgnoreCurrentPageChanges (bool bIgnore);
155 
156     /** creates and inserts an empty slide for the given paragraph. */
157     SdPage* InsertSlideForParagraph( Paragraph* pPara );
158 
159     void UpdateParagraph( sal_Int32 nPara );
160 
161 protected:
162     virtual void OnBeginPasteOrDrop( PasteOrDropInfos* pInfo ) override;
163     virtual void OnEndPasteOrDrop( PasteOrDropInfos* pInfo ) override;
164 
165 private:
166     /** call this method before you do anything that can modify the outliner
167         and or the drawing document model. It will create needed undo actions */
168     void BeginModelChange();
169 
170     /** call this method after BeginModelChange(), when all possible model
171         changes are done. */
172     void EndModelChange();
173 
174     /** merge edit engine undo actions if possible */
175     void TryToMergeUndoActions();
176 
177     /** updates all changes in the outliner model to the draw model */
178     void UpdateDocument();
179 
180     OutlineViewShell&   mrOutlineViewShell;
181     SdOutliner&         mrOutliner;
182     std::unique_ptr<OutlinerView> mpOutlinerViews[MAX_OUTLINERVIEWS];
183 
184     std::vector<Paragraph*> maOldParaOrder;
185     std::vector<Paragraph*> maSelectedParas;
186 
187     sal_Int32               mnPagesToProcess;    // for the progress bar
188     sal_Int32               mnPagesProcessed;
189 
190     bool                mbFirstPaint;
191 
192     sal_uLong               mnPaperWidth;
193 
194     std::unique_ptr<SfxProgress> mpProgress;
195 
196     /** stores the last used document color.
197         this is changed in onUpdateStyleSettings()
198     */
199     Color maDocColor;
200 
201     /** updates the high contrast settings and document color if they changed.
202         @param bForceUpdate forces the method to set all style settings
203     */
204     void onUpdateStyleSettings( bool bForceUpdate );
205 
206     /** this link is called from the vcl application when the stylesettings
207         change. Its only purpose is to call onUpdateStyleSettings() then.
208     */
209     DECL_LINK( AppEventListenerHdl, VclSimpleEvent&, void );
210 
211     DECL_LINK(EventMultiplexerListener, sd::tools::EventMultiplexerEvent&, void);
212 
213     /** holds a model guard during drag and drop between BeginMovingHdl and EndMovingHdl */
214     std::unique_ptr<OutlineViewModelChangeGuard, o3tl::default_delete<OutlineViewModelChangeGuard>> maDragAndDropModelGuard;
215 
216     SvxLRSpaceItem maLRSpaceItem;
217     Image maSlideImage;
218 };
219 
220 // calls IgnoreCurrentPageChangesLevel with true in ctor and with false in dtor
221 class OutlineViewPageChangesGuard
222 {
223 public:
224     OutlineViewPageChangesGuard( OutlineView* pView );
225     ~OutlineViewPageChangesGuard();
226 private:
227     OutlineView* mpView;
228 };
229 
230 // calls BeginModelChange() on c'tor and EndModelChange() on d'tor
231 class OutlineViewModelChangeGuard
232 {
233 public:
234     OutlineViewModelChangeGuard( OutlineView& rView );
235     ~OutlineViewModelChangeGuard() COVERITY_NOEXCEPT_FALSE;
236 private:
237     OutlineView& mrView;
238 };
239 
240 } // end of namespace sd
241 
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
243