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 #include <model/SlsPageDescriptor.hxx>
21 
22 #include <sdpage.hxx>
23 
24 using namespace ::com::sun::star::uno;
25 using namespace ::com::sun::star;
26 
27 namespace sd::slidesorter::model {
28 
PageDescriptor(const Reference<drawing::XDrawPage> & rxPage,SdPage * pPage,const sal_Int32 nIndex)29 PageDescriptor::PageDescriptor (
30     const Reference<drawing::XDrawPage>& rxPage,
31     SdPage* pPage,
32     const sal_Int32 nIndex)
33     : mpPage(pPage),
34       mxPage(rxPage),
35       mpMasterPage(nullptr),
36       mnIndex(nIndex),
37       maBoundingBox(),
38       maVisualState(nIndex),
39       mbIsSelected(false),
40       mbWasSelected(false),
41       mbIsVisible(false),
42       mbIsFocused(false),
43       mbIsCurrent(false),
44       mbIsMouseOver(false),
45       mbHasTransition(false)
46 {
47     assert(mpPage);
48     assert(mpPage == SdPage::getImplementation(rxPage));
49     if (mpPage != nullptr)
50     {
51         if (mpPage->TRG_HasMasterPage())
52             mpMasterPage = &mpPage->TRG_GetMasterPage();
53         if (mpPage->getTransitionType() > 0)
54             mbHasTransition = true;
55     }
56 }
57 
~PageDescriptor()58 PageDescriptor::~PageDescriptor()
59 {
60 }
61 
SetPageIndex(const sal_Int32 nNewIndex)62 void PageDescriptor::SetPageIndex (const sal_Int32 nNewIndex)
63 {
64     mnIndex = nNewIndex;
65     maVisualState.mnPageId = nNewIndex;
66 }
67 
UpdateMasterPage()68 bool PageDescriptor::UpdateMasterPage()
69 {
70     const SdrPage* pMaster = nullptr;
71     if (mpPage!=nullptr && mpPage->TRG_HasMasterPage())
72         pMaster = &mpPage->TRG_GetMasterPage();
73     if (mpMasterPage != pMaster)
74     {
75         mpMasterPage = pMaster;
76         return true;
77     }
78     else
79         return false;
80 }
81 
UpdateTransitionFlag()82 bool PageDescriptor::UpdateTransitionFlag()
83 {
84     bool bHasSlideTransition (false);
85     if (mpPage != nullptr)
86         bHasSlideTransition = mpPage->getTransitionType() > 0;
87     if (bHasSlideTransition != mbHasTransition)
88     {
89         mbHasTransition = bHasSlideTransition;
90         return true;
91     }
92     else
93         return false;
94 }
95 
HasState(const State eState) const96 bool PageDescriptor::HasState (const State eState) const
97 {
98     switch (eState)
99     {
100         case ST_Visible:
101             return mbIsVisible;
102 
103         case ST_Selected:
104             return mbIsSelected;
105 
106         case ST_WasSelected:
107             return mbWasSelected;
108 
109         case ST_Focused:
110             return mbIsFocused;
111 
112         case ST_MouseOver:
113             return mbIsMouseOver;
114 
115         case ST_Current:
116             return mbIsCurrent;
117 
118         case ST_Excluded:
119             return mpPage!=nullptr && mpPage->IsExcluded();
120 
121         default:
122             assert(false);
123             return false;
124     }
125 }
126 
SetState(const State eState,const bool bNewStateValue)127 bool PageDescriptor::SetState (const State eState, const bool bNewStateValue)
128 {
129     bool bModified (false);
130     switch (eState)
131     {
132         case ST_Visible:
133             bModified = (bNewStateValue!=mbIsVisible);
134             if (bModified)
135                 mbIsVisible = bNewStateValue;
136             break;
137 
138         case ST_Selected:
139             bModified = (bNewStateValue!=mbIsSelected);
140             if (bModified)
141                 mbIsSelected = bNewStateValue;
142             break;
143 
144         case ST_WasSelected:
145             bModified = (bNewStateValue!=mbWasSelected);
146             if (bModified)
147                 mbWasSelected = bNewStateValue;
148             break;
149 
150         case ST_Focused:
151             bModified = (bNewStateValue!=mbIsFocused);
152             if (bModified)
153                 mbIsFocused = bNewStateValue;
154             break;
155 
156         case ST_MouseOver:
157             bModified = (bNewStateValue!=mbIsMouseOver);
158             if (bModified)
159                 mbIsMouseOver = bNewStateValue;
160             break;
161 
162         case ST_Current:
163             bModified = (bNewStateValue!=mbIsCurrent);
164             if (bModified)
165                 mbIsCurrent = bNewStateValue;
166             break;
167 
168         case ST_Excluded:
169             // This is a state of the page and has to be handled differently
170             // from the view-only states.
171             if (mpPage != nullptr)
172                 if (bNewStateValue != mpPage->IsExcluded())
173                 {
174                     mpPage->SetExcluded(bNewStateValue);
175                     bModified = true;
176                 }
177             break;
178     }
179 
180     return bModified;
181 }
182 
GetCoreSelection()183 bool PageDescriptor::GetCoreSelection()
184 {
185     if (mpPage!=nullptr && mpPage->IsSelected() != mbIsSelected)
186         return SetState(ST_Selected, !mbIsSelected);
187     else
188         return false;
189 }
190 
SetCoreSelection()191 void PageDescriptor::SetCoreSelection()
192 {
193     if (mpPage != nullptr)
194         if (HasState(ST_Selected))
195             mpPage->SetSelected(true);
196         else
197             mpPage->SetSelected(false);
198     else
199     {
200         assert(mpPage!=nullptr);
201     }
202 }
203 
GetBoundingBox() const204 ::tools::Rectangle PageDescriptor::GetBoundingBox() const
205 {
206     ::tools::Rectangle aBox (maBoundingBox);
207     const Point aOffset (maVisualState.GetLocationOffset());
208     aBox.Move(aOffset.X(), aOffset.Y());
209     return aBox;
210 }
211 
GetLocation(const bool bIgnoreOffset) const212 Point PageDescriptor::GetLocation (const bool bIgnoreOffset) const
213 {
214     if (bIgnoreOffset)
215         return maBoundingBox.TopLeft();
216     else
217         return maBoundingBox.TopLeft() + maVisualState.GetLocationOffset();
218 }
219 
SetBoundingBox(const::tools::Rectangle & rBoundingBox)220 void PageDescriptor::SetBoundingBox (const ::tools::Rectangle& rBoundingBox)
221 {
222     maBoundingBox = rBoundingBox;
223 }
224 
225 } // end of namespace ::sd::slidesorter::model
226 
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
228