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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #include "model/SlsPageDescriptor.hxx"
28 
29 #include "sdpage.hxx"
30 #include "drawdoc.hxx"
31 
32 #include <svx/svdopage.hxx>
33 #include <svx/svdpagv.hxx>
34 #include <svx/sdr/contact/viewcontact.hxx>
35 #include <svx/sdr/contact/viewobjectcontact.hxx>
36 
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star;
39 
40 namespace sd {  namespace slidesorter { namespace model {
41 
42 
PageDescriptor(const Reference<drawing::XDrawPage> & rxPage,SdPage * pPage,const sal_Int32 nIndex)43 PageDescriptor::PageDescriptor (
44     const Reference<drawing::XDrawPage>& rxPage,
45     SdPage* pPage,
46     const sal_Int32 nIndex)
47     : mpPage(pPage),
48       mxPage(rxPage),
49       mpMasterPage(NULL),
50       mnIndex(nIndex),
51       maBoundingBox(),
52       maVisualState(nIndex),
53       mbIsSelected(false),
54       mbWasSelected(false),
55       mbIsVisible(false),
56       mbIsFocused(false),
57       mbIsCurrent(false),
58       mbIsMouseOver(false),
59       mbHasTransition(false)
60 {
61     OSL_ASSERT(mpPage);
62     OSL_ASSERT(mpPage == SdPage::getImplementation(rxPage));
63     if (mpPage != NULL)
64     {
65         if (mpPage->TRG_HasMasterPage())
66             mpMasterPage = &mpPage->TRG_GetMasterPage();
67         if (mpPage->getTransitionType() > 0)
68             mbHasTransition = true;
69     }
70 }
71 
72 
73 
74 
~PageDescriptor(void)75 PageDescriptor::~PageDescriptor (void)
76 {
77 }
78 
79 
80 
81 
GetPage(void) const82 SdPage* PageDescriptor::GetPage (void) const
83 {
84     return mpPage;
85 }
86 
87 
88 
89 
GetXDrawPage(void) const90 Reference<drawing::XDrawPage> PageDescriptor::GetXDrawPage (void) const
91 {
92     return mxPage;
93 }
94 
95 
96 
97 
GetPageIndex(void) const98 sal_Int32 PageDescriptor::GetPageIndex (void) const
99 {
100     return mnIndex;
101 }
102 
103 
104 
105 
SetPageIndex(const sal_Int32 nNewIndex)106 void PageDescriptor::SetPageIndex (const sal_Int32 nNewIndex)
107 {
108     mnIndex = nNewIndex;
109     maVisualState.mnPageId = nNewIndex;
110 }
111 
112 
113 
114 
UpdateMasterPage(void)115 bool PageDescriptor::UpdateMasterPage (void)
116 {
117     const SdrPage* pMaster = NULL;
118     if (mpPage!=NULL && mpPage->TRG_HasMasterPage())
119         pMaster = &mpPage->TRG_GetMasterPage();
120     if (mpMasterPage != pMaster)
121     {
122         mpMasterPage = pMaster;
123         return true;
124     }
125     else
126         return false;
127 }
128 
129 
130 
131 
UpdateTransitionFlag(void)132 bool PageDescriptor::UpdateTransitionFlag (void)
133 {
134     bool bHasSlideTransition (false);
135     if (mpPage != NULL)
136         bHasSlideTransition = mpPage->getTransitionType() > 0;
137     if (bHasSlideTransition != mbHasTransition)
138     {
139         mbHasTransition = bHasSlideTransition;
140         return true;
141     }
142     else
143         return false;
144 }
145 
146 
147 
148 
HasState(const State eState) const149 bool PageDescriptor::HasState (const State eState) const
150 {
151     switch (eState)
152     {
153         case ST_Visible:
154             return mbIsVisible;
155 
156         case ST_Selected:
157             return mbIsSelected;
158 
159         case ST_WasSelected:
160             return mbWasSelected;
161 
162         case ST_Focused:
163             return mbIsFocused;
164 
165         case ST_MouseOver:
166             return mbIsMouseOver;
167 
168         case ST_Current:
169             return mbIsCurrent;
170 
171         case ST_Excluded:
172 			return mpPage!=NULL && mpPage->IsExcluded();
173 
174         default:
175             OSL_ASSERT(false);
176             return false;
177     }
178 }
179 
180 
181 
182 
SetState(const State eState,const bool bNewStateValue)183 bool PageDescriptor::SetState (const State eState, const bool bNewStateValue)
184 {
185     bool bModified (false);
186     switch (eState)
187     {
188         case ST_Visible:
189             bModified = (bNewStateValue!=mbIsVisible);
190             if (bModified)
191                 mbIsVisible = bNewStateValue;
192             break;
193 
194         case ST_Selected:
195             bModified = (bNewStateValue!=mbIsSelected);
196             if (bModified)
197                 mbIsSelected = bNewStateValue;
198             break;
199 
200         case ST_WasSelected:
201             bModified = (bNewStateValue!=mbWasSelected);
202             if (bModified)
203                 mbWasSelected = bNewStateValue;
204             break;
205 
206         case ST_Focused:
207             bModified = (bNewStateValue!=mbIsFocused);
208             if (bModified)
209                 mbIsFocused = bNewStateValue;
210             break;
211 
212         case ST_MouseOver:
213             bModified = (bNewStateValue!=mbIsMouseOver);
214             if (bModified)
215                 mbIsMouseOver = bNewStateValue;
216             break;
217 
218         case ST_Current:
219             bModified = (bNewStateValue!=mbIsCurrent);
220             if (bModified)
221                 mbIsCurrent = bNewStateValue;
222             break;
223 
224         case ST_Excluded:
225             // This is a state of the page and has to be handled differently
226             // from the view-only states.
227             if (mpPage != NULL)
228                 if (bNewStateValue != (mpPage->IsExcluded()==sal_True))
229                 {
230                     mpPage->SetExcluded(bNewStateValue);
231                     bModified = true;
232                 }
233             break;
234     }
235 
236     if (bModified)
237         maVisualState.UpdateVisualState(*this);
238     return bModified;
239 }
240 
241 
242 
243 
GetVisualState(void)244 VisualState& PageDescriptor::GetVisualState (void)
245 {
246     return maVisualState;
247 }
248 
249 
250 
251 
GetCoreSelection(void)252 bool PageDescriptor::GetCoreSelection (void)
253 {
254     if (mpPage!=NULL && (mpPage->IsSelected()==sal_True) != mbIsSelected)
255         return SetState(ST_Selected, !mbIsSelected);
256     else
257         return false;
258 }
259 
260 
261 
262 
SetCoreSelection(void)263 void PageDescriptor::SetCoreSelection (void)
264 {
265     if (mpPage != NULL)
266         if (HasState(ST_Selected))
267             mpPage->SetSelected(sal_True);
268         else
269             mpPage->SetSelected(sal_False);
270     else
271     {
272         OSL_ASSERT(mpPage!=NULL);
273     }
274 }
275 
276 
277 
278 
GetBoundingBox(void) const279 Rectangle PageDescriptor::GetBoundingBox (void) const
280 {
281     Rectangle aBox (maBoundingBox);
282     const Point aOffset (maVisualState.GetLocationOffset());
283     aBox.Move(aOffset.X(), aOffset.Y());
284     return aBox;
285 }
286 
287 
288 
289 
GetLocation(const bool bIgnoreOffset) const290 Point PageDescriptor::GetLocation (const bool bIgnoreOffset) const
291 {
292     if (bIgnoreOffset)
293         return maBoundingBox.TopLeft();
294     else
295         return maBoundingBox.TopLeft() + maVisualState.GetLocationOffset();
296 }
297 
298 
299 
300 
SetBoundingBox(const Rectangle & rBoundingBox)301 void PageDescriptor::SetBoundingBox (const Rectangle& rBoundingBox)
302 {
303     maBoundingBox = rBoundingBox;
304 }
305 
306 
307 
308 } } } // end of namespace ::sd::slidesorter::model
309