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