bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / slidesorter / model / SlsPageDescriptor.cxx
blobe84b4cd22eb581f2cc1d4684336819c974aea50d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "model/SlsPageDescriptor.hxx"
22 #include "sdpage.hxx"
23 #include "drawdoc.hxx"
25 #include <svx/svdopage.hxx>
26 #include <svx/svdpagv.hxx>
27 #include <svx/sdr/contact/viewcontact.hxx>
28 #include <svx/sdr/contact/viewobjectcontact.hxx>
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star;
33 namespace sd { namespace slidesorter { namespace model {
35 PageDescriptor::PageDescriptor (
36 const Reference<drawing::XDrawPage>& rxPage,
37 SdPage* pPage,
38 const sal_Int32 nIndex)
39 : mpPage(pPage),
40 mxPage(rxPage),
41 mpMasterPage(NULL),
42 mnIndex(nIndex),
43 maBoundingBox(),
44 maVisualState(nIndex),
45 mbIsSelected(false),
46 mbWasSelected(false),
47 mbIsVisible(false),
48 mbIsFocused(false),
49 mbIsCurrent(false),
50 mbIsMouseOver(false),
51 mbHasTransition(false)
53 OSL_ASSERT(mpPage);
54 OSL_ASSERT(mpPage == SdPage::getImplementation(rxPage));
55 if (mpPage != NULL)
57 if (mpPage->TRG_HasMasterPage())
58 mpMasterPage = &mpPage->TRG_GetMasterPage();
59 if (mpPage->getTransitionType() > 0)
60 mbHasTransition = true;
64 PageDescriptor::~PageDescriptor()
68 void PageDescriptor::SetPageIndex (const sal_Int32 nNewIndex)
70 mnIndex = nNewIndex;
71 maVisualState.mnPageId = nNewIndex;
74 bool PageDescriptor::UpdateMasterPage()
76 const SdrPage* pMaster = NULL;
77 if (mpPage!=NULL && mpPage->TRG_HasMasterPage())
78 pMaster = &mpPage->TRG_GetMasterPage();
79 if (mpMasterPage != pMaster)
81 mpMasterPage = pMaster;
82 return true;
84 else
85 return false;
88 bool PageDescriptor::UpdateTransitionFlag()
90 bool bHasSlideTransition (false);
91 if (mpPage != NULL)
92 bHasSlideTransition = mpPage->getTransitionType() > 0;
93 if (bHasSlideTransition != mbHasTransition)
95 mbHasTransition = bHasSlideTransition;
96 return true;
98 else
99 return false;
102 bool PageDescriptor::HasState (const State eState) const
104 switch (eState)
106 case ST_Visible:
107 return mbIsVisible;
109 case ST_Selected:
110 return mbIsSelected;
112 case ST_WasSelected:
113 return mbWasSelected;
115 case ST_Focused:
116 return mbIsFocused;
118 case ST_MouseOver:
119 return mbIsMouseOver;
121 case ST_Current:
122 return mbIsCurrent;
124 case ST_Excluded:
125 return mpPage!=NULL && mpPage->IsExcluded();
127 default:
128 OSL_ASSERT(false);
129 return false;
133 bool PageDescriptor::SetState (const State eState, const bool bNewStateValue)
135 bool bModified (false);
136 switch (eState)
138 case ST_Visible:
139 bModified = (bNewStateValue!=mbIsVisible);
140 if (bModified)
141 mbIsVisible = bNewStateValue;
142 break;
144 case ST_Selected:
145 bModified = (bNewStateValue!=mbIsSelected);
146 if (bModified)
147 mbIsSelected = bNewStateValue;
148 break;
150 case ST_WasSelected:
151 bModified = (bNewStateValue!=mbWasSelected);
152 if (bModified)
153 mbWasSelected = bNewStateValue;
154 break;
156 case ST_Focused:
157 bModified = (bNewStateValue!=mbIsFocused);
158 if (bModified)
159 mbIsFocused = bNewStateValue;
160 break;
162 case ST_MouseOver:
163 bModified = (bNewStateValue!=mbIsMouseOver);
164 if (bModified)
165 mbIsMouseOver = bNewStateValue;
166 break;
168 case ST_Current:
169 bModified = (bNewStateValue!=mbIsCurrent);
170 if (bModified)
171 mbIsCurrent = bNewStateValue;
172 break;
174 case ST_Excluded:
175 // This is a state of the page and has to be handled differently
176 // from the view-only states.
177 if (mpPage != NULL)
178 if (bNewStateValue != mpPage->IsExcluded())
180 mpPage->SetExcluded(bNewStateValue);
181 bModified = true;
183 break;
186 if (bModified)
187 maVisualState.UpdateVisualState(*this);
188 return bModified;
191 bool PageDescriptor::GetCoreSelection()
193 if (mpPage!=NULL && mpPage->IsSelected() != mbIsSelected)
194 return SetState(ST_Selected, !mbIsSelected);
195 else
196 return false;
199 void PageDescriptor::SetCoreSelection()
201 if (mpPage != NULL)
202 if (HasState(ST_Selected))
203 mpPage->SetSelected(true);
204 else
205 mpPage->SetSelected(false);
206 else
208 OSL_ASSERT(mpPage!=NULL);
212 Rectangle PageDescriptor::GetBoundingBox() const
214 Rectangle aBox (maBoundingBox);
215 const Point aOffset (maVisualState.GetLocationOffset());
216 aBox.Move(aOffset.X(), aOffset.Y());
217 return aBox;
220 Point PageDescriptor::GetLocation (const bool bIgnoreOffset) const
222 if (bIgnoreOffset)
223 return maBoundingBox.TopLeft();
224 else
225 return maBoundingBox.TopLeft() + maVisualState.GetLocationOffset();
228 void PageDescriptor::SetBoundingBox (const Rectangle& rBoundingBox)
230 maBoundingBox = rBoundingBox;
233 } } } // end of namespace ::sd::slidesorter::model
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */