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 #ifndef SD_SLIDESORTER_SLIDE_SORTER_VIEW_HXX
25 #define SD_SLIDESORTER_SLIDE_SORTER_VIEW_HXX
26 
27 #include "SlideSorter.hxx"
28 #include "model/SlsPageDescriptor.hxx"
29 #include "model/SlsSharedPageDescriptor.hxx"
30 #include "view/SlsLayouter.hxx"
31 #include "view/SlsILayerPainter.hxx"
32 
33 #include "View.hxx"
34 #include <sfx2/viewfrm.hxx>
35 #include "pres.hxx"
36 #include <tools/gen.hxx>
37 #include <svx/svdmodel.hxx>
38 #include <vcl/region.hxx>
39 #include <vcl/outdev.hxx>
40 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
41 #include <memory>
42 #include <boost/shared_ptr.hpp>
43 #include <boost/noncopyable.hpp>
44 
45 class Point;
46 
47 namespace sd { namespace slidesorter { namespace controller {
48 class SlideSorterController;
49 class Properties;
50 } } }
51 
52 namespace sd { namespace slidesorter { namespace cache {
53 class PageCache;
54 } } }
55 
56 namespace sd { namespace slidesorter { namespace model {
57 class SlideSorterModel;
58 } } }
59 
60 namespace sd { namespace slidesorter { namespace view {
61 
62 class ButtonBar;
63 class LayeredDevice;
64 class Layouter;
65 class PageObjectPainter;
66 class SelectionPainter;
67 class ToolTip;
68 
69 
70 class SlideSorterView
71     : public sd::View,
72       public ::boost::noncopyable
73 {
74 public:
75     TYPEINFO ();
76 
77     /** Create a new view for the slide sorter.
78         @param rViewShell
79             This reference is simply passed to the base class and not used
80             by this class.
81 
82     */
83     SlideSorterView (SlideSorter& rSlideSorter);
84     void Init (void);
85 
86     virtual ~SlideSorterView (void);
87     void Dispose (void);
88 
89     /** Set the general way of layouting the page objects.  Note that this
90         method does not trigger any repaints or layouts.
91     */
92     bool SetOrientation (const Layouter::Orientation eOrientation);
93     Layouter::Orientation GetOrientation (void) const;
94 
95     void RequestRepaint (void);
96     void RequestRepaint (const model::SharedPageDescriptor& rDescriptor);
97     void RequestRepaint (const Rectangle& rRepaintBox);
98     void RequestRepaint (const Region& rRepaintRegion);
99 
100     Rectangle GetModelArea (void);
101 
102     /** Return the index of the page that is rendered at the given position.
103         @param rPosition
104             The position is expected to be in pixel coordinates.
105         @return
106             The returned index is -1 when there is no page object at the
107             given position.
108     */
109     sal_Int32 GetPageIndexAtPoint (const Point& rPosition) const;
110 
111     view::Layouter& GetLayouter (void);
112 
113     virtual void ModelHasChanged (void);
114 
115     void LocalModelHasChanged(void);
116 
117     /** This method is typically called before a model change takes place.
118         All references to model data are released.  PostModelChange() has to
119         be called to complete the handling of the model change.  When the
120         calls to Pre- and PostModelChange() are very close to each other you
121         may call HandleModelChange() instead.
122     */
123     void PreModelChange (void);
124 
125     /** This method is typically called after a model change took place.
126         References to model data are re-allocated.  Call this method only
127         after PreModelChange() has been called.
128     */
129     void PostModelChange (void);
130 
131     /** This method is a convenience function that simply calls
132         PreModelChange() and then PostModelChange().
133     */
134     void HandleModelChange (void);
135 
136     void HandleDrawModeChange (void);
137 
138     virtual void Resize (void);
139     virtual void CompleteRedraw (
140         OutputDevice* pDevice,
141         const Region& rPaintArea,
142         sdr::contact::ViewObjectContactRedirector* pRedirector = NULL);
143     void Paint (OutputDevice& rDevice, const Rectangle& rRepaintArea);
144 
145     virtual void ConfigurationChanged (
146         utl::ConfigurationBroadcaster* pBroadcaster,
147         sal_uInt32 nHint);
148 
149     void HandleDataChangeEvent (void);
150 
151     void Layout (void);
152     /** This tells the view that it has to re-determine the visibility of
153         the page objects before painting them the next time.
154     */
155     void InvalidatePageObjectVisibilities (void);
156 
157     /** Return the window to which this view renders its output.
158     */
159     //    ::boost::shared_ptr<sd::Window> GetWindow (void) const;
160 
161     ::boost::shared_ptr<cache::PageCache> GetPreviewCache (void);
162 
163     /** Set the bounding box of the insertion marker in model coordinates.
164 
165         It will be painted as a dark rectangle that fills the given box.
166     */
167     void SetInsertionMarker (const Rectangle& rBBox);
168 
169     /** Specify whether the insertion marker will be painted or not.
170     */
171     void SetInsertionMarkerVisibility (bool bVisible);
172 
173     /** Set the size and position of the selection rectangle.
174 
175         It will be painted as a dashed rectangle.
176     */
177     void SetSelectionRectangle (const Rectangle& rBox);
178 
179     /** Specify whether the selection rectangle will be painted or not.
180     */
181     void SetSelectionRectangleVisibility (bool bVisible);
182 
183     /** Return the range of currently visible page objects including the
184         first and last one in that range.
185         @return
186             The returned pair of page object indices is empty when the
187             second index is lower than the first.
188     */
189     Pair GetVisiblePageRange (void);
190 
191     /** Add a shape to the page.  Typically used from inside
192         PostModelChange().
193     */
194     //    void AddSdrObject (SdrObject& rObject);
195 
196     /** Add a listener that is called when the set of visible slides.
197         @param rListener
198             When this method is called multiple times for the same listener
199             the second and all following calls are ignored.  Each listener
200             is added only once.
201     */
202     void AddVisibilityChangeListener (const Link& rListener);
203 
204     /** Remove a listener that is called when the set of visible slides changes.
205         @param rListener
206             It is save to pass a listener that was not added or has been
207             removed previously.  Such calls are ignored.
208     */
209     void RemoveVisibilityChangeListener (const Link& rListener);
210 
211     /** The page under the mouse is not highlighted in some contexts.  Call
212         this method on context changes.
213     */
214     void UpdatePageUnderMouse (bool bAnimate);
215     void UpdatePageUnderMouse (
216         const Point& rMousePosition,
217         const bool bIsMouseButtonDown,
218         const bool bAnimate = true);
219     void UpdatePageUnderMouse (
220         const model::SharedPageDescriptor& rpDescriptor,
221         const Point& rMousePosition,
222         const bool bIsMouseButtonDown,
223         const bool bAnimate = true);
224     void SetPageUnderMouse (
225         const model::SharedPageDescriptor& rpDescriptor,
226         const bool bAnimate = true);
227 
228     bool SetState (
229         const model::SharedPageDescriptor& rpDescriptor,
230         const model::PageDescriptor::State eState,
231         const bool bStateValue,
232         const bool bAnimate = true);
233 
234     void UpdateOrientation (void);
235 
236     ::boost::shared_ptr<PageObjectPainter> GetPageObjectPainter (void);
237     ::boost::shared_ptr<LayeredDevice> GetLayeredDevice (void) const;
238 
239     class DrawLock
240     {
241     public:
242         DrawLock (view::SlideSorterView& rView, const SharedSdWindow& rpWindow);
243         DrawLock (SlideSorter& rSlideSorter);
244         ~DrawLock (void);
245         /** When the DrawLock is disposed then it will not request a repaint
246             on destruction.
247         */
248         void Dispose (void);
249     private:
250         view::SlideSorterView& mrView;
251         SharedSdWindow mpWindow;
252     };
253 
254     ButtonBar& GetButtonBar (void) const;
255     ToolTip& GetToolTip (void) const;
256 
257     virtual void DragFinished (sal_Int8 nDropAction);
258 
259 protected:
260     virtual void Notify (SfxBroadcaster& rBroadcaster, const SfxHint& rHint);
261 
262 private:
263     SlideSorter& mrSlideSorter;
264     model::SlideSorterModel& mrModel;
265     bool mbIsDisposed;
266     ::std::auto_ptr<Layouter> mpLayouter;
267     bool mbPageObjectVisibilitiesValid;
268     ::boost::shared_ptr<cache::PageCache> mpPreviewCache;
269     ::boost::shared_ptr<LayeredDevice> mpLayeredDevice;
270     Range maVisiblePageRange;
271     bool mbModelChangedWhileModifyEnabled;
272     Size maPreviewSize;
273     bool mbPreciousFlagUpdatePending;
274     Layouter::Orientation meOrientation;
275     ::boost::shared_ptr<controller::Properties> mpProperties;
276     model::SharedPageDescriptor mpPageUnderMouse;
277     sal_Int32 mnButtonUnderMouse;
278     ::boost::shared_ptr<PageObjectPainter> mpPageObjectPainter;
279     ::boost::shared_ptr<SelectionPainter> mpSelectionPainter;
280     Region maRedrawRegion;
281     SharedILayerPainter mpBackgroundPainter;
282     ::boost::scoped_ptr<ButtonBar> mpButtonBar;
283     ::boost::scoped_ptr<ToolTip> mpToolTip;
284     bool mbIsRearrangePending;
285     ::std::vector<Link> maVisibilityChangeListeners;
286 
287     /** Determine the visibility of all page objects.
288     */
289     void DeterminePageObjectVisibilities (void);
290 
291     void UpdatePreciousFlags (void);
292     void RequestRearrange (void);
293     void Rearrange (void);
294 };
295 
296 
297 } } } // end of namespace ::sd::slidesorter::view
298 
299 #endif
300