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_INSERTION_INDICATOR_HANDLER_HXX
25 #define SD_SLIDESORTER_INSERTION_INDICATOR_HANDLER_HXX
26 
27 #include "view/SlsInsertAnimator.hxx"
28 
29 #include "view/SlsLayouter.hxx"
30 #include "sdxfer.hxx"
31 
32 
33 namespace sd { namespace slidesorter { class SlideSorter; } }
34 namespace sd { namespace slidesorter { namespace model {
35 class PageEnumeration;
36 } } }
37 namespace sd { namespace slidesorter { namespace view {
38 class InsertAnimator;
39 class InsertionIndicatorOverlay;
40 } } }
41 
42 
43 namespace sd { namespace slidesorter { namespace controller {
44 
45 class Transferable;
46 
47 
48 /** Manage the visibility and location of the insertion indicator.  Its
49     actual display is controlled by the InsertionIndicatorOverlay.
50 */
51 class InsertionIndicatorHandler
52 {
53 public:
54     InsertionIndicatorHandler (SlideSorter& rSlideSorter);
55     ~InsertionIndicatorHandler (void);
56 
57     enum Mode { CopyMode, MoveMode, UnknownMode };
58     static Mode GetModeFromDndAction (const sal_Int8 nDndAction);
59 
60     /** Activate the insertion marker at the given coordinates.
61     */
62     void Start (const bool bIsOverSourceView);
63 
64     /** Deactivate the insertion marker.
65     */
66     void End (const controller::Animator::AnimationMode eMode);
67 
68     /** This context make sure that the insertion indicator is shown
69         (provided that the clipboard is not empty) while the context is
70         alive.  Typically used while a context menu is displayed.
71     */
72     class ForceShowContext
73     {
74     public:
75         ForceShowContext (const ::boost::shared_ptr<InsertionIndicatorHandler>& rpHandler);
76         ~ForceShowContext (void);
77     private:
78         const ::boost::shared_ptr<InsertionIndicatorHandler> mpHandler;
79     };
80 
81     /** Update the indicator icon from the current transferable (from the
82         clipboard or an active drag and drop operation.)
83     */
84     void UpdateIndicatorIcon (const SdTransferable* pTransferable);
85 
86     /** Set the position of the insertion marker to the given coordinates.
87     */
88     void UpdatePosition (
89         const Point& rMouseModelPosition,
90         const Mode eMode);
91     void UpdatePosition (
92         const Point& rMouseModelPosition,
93         const sal_Int8 nDndAction);
94 
95     /** Return whether the insertion marker is active.
96     */
97     bool IsActive (void) const;
98 
99     /** Return the insertion index that corresponds with the current
100         graphical location of the insertion indicator.
101     */
102     sal_Int32 GetInsertionPageIndex (void) const;
103 
104     /** Determine whether moving the current selection to the current
105         position of the insertion marker would alter the document.  This
106         would be the case when the selection is not consecutive or would be
107         moved to a position outside and not adjacent to the selection.
108     */
109     bool IsInsertionTrivial (
110         const sal_Int32 nInsertionIndex,
111         const Mode eMode) const;
112     /** This method is like the other variant.  It operates implicitly
113         on the current insertion index as would be returned by
114         GetInsertionPageIndex().
115     */
116     bool IsInsertionTrivial (const sal_Int8 nDndAction);
117 
118 private:
119     SlideSorter& mrSlideSorter;
120     ::boost::shared_ptr<view::InsertAnimator> mpInsertAnimator;
121     ::boost::shared_ptr<view::InsertionIndicatorOverlay> mpInsertionIndicatorOverlay;
122     view::InsertPosition maInsertPosition;
123     Mode meMode;
124     bool mbIsInsertionTrivial;
125     bool mbIsActive;
126     bool mbIsReadOnly;
127     bool mbIsOverSourceView;
128     Size maIconSize;
129     bool mbIsForcedShow;
130 
131     void SetPosition (
132         const Point& rPoint,
133         const Mode eMode);
134     ::boost::shared_ptr<view::InsertAnimator> GetInsertAnimator (void);
135 
136     /** Make the insertion indicator visible (that is the show part) and
137         keep it visible, even when the mouse leaves the window (that is the
138         force part).  We need this when a context menu is displayed (mouse
139         over the popup menu triggers a mouse leave event) while the
140         insertion indicator remains visible in the background.
141 
142         In effect all calls to End() are ignored until ForceEnd() is called.
143     */
144     void ForceShow (void);
145     void ForceEnd (void);
146 };
147 
148 
149 } } } // end of namespace ::sd::slidesorter::controller
150 
151 #endif
152