tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sd / source / ui / slidesorter / model / SlsPageDescriptor.cxx
blob5118cf58ec0990a7df3797114d397418dde877af
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>
24 using namespace ::com::sun::star::uno;
25 using namespace ::com::sun::star;
27 namespace sd::slidesorter::model {
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 maVisualState(nIndex),
38 mbIsSelected(false),
39 mbWasSelected(false),
40 mbIsVisible(false),
41 mbIsFocused(false),
42 mbIsCurrent(false),
43 mbIsMouseOver(false),
44 mbHasTransition(false)
46 assert(mpPage);
47 assert(mpPage == SdPage::getImplementation(rxPage));
48 if (mpPage != nullptr)
50 if (mpPage->TRG_HasMasterPage())
51 mpMasterPage = &mpPage->TRG_GetMasterPage();
52 if (mpPage->getTransitionType() > 0)
53 mbHasTransition = true;
57 PageDescriptor::~PageDescriptor()
61 void PageDescriptor::SetPageIndex (const sal_Int32 nNewIndex)
63 mnIndex = nNewIndex;
64 maVisualState.mnPageId = nNewIndex;
67 bool PageDescriptor::UpdateMasterPage()
69 const SdrPage* pMaster = nullptr;
70 if (mpPage!=nullptr && mpPage->TRG_HasMasterPage())
71 pMaster = &mpPage->TRG_GetMasterPage();
72 if (mpMasterPage != pMaster)
74 mpMasterPage = pMaster;
75 return true;
77 else
78 return false;
81 bool PageDescriptor::UpdateTransitionFlag()
83 bool bHasSlideTransition (false);
84 if (mpPage != nullptr)
85 bHasSlideTransition = mpPage->getTransitionType() > 0;
86 if (bHasSlideTransition != mbHasTransition)
88 mbHasTransition = bHasSlideTransition;
89 return true;
91 else
92 return false;
95 bool PageDescriptor::HasState (const State eState) const
97 switch (eState)
99 case ST_Visible:
100 return mbIsVisible;
102 case ST_Selected:
103 return mbIsSelected;
105 case ST_WasSelected:
106 return mbWasSelected;
108 case ST_Focused:
109 return mbIsFocused;
111 case ST_MouseOver:
112 return mbIsMouseOver;
114 case ST_Current:
115 return mbIsCurrent;
117 case ST_Excluded:
118 return mpPage!=nullptr && mpPage->IsExcluded();
120 default:
121 assert(false);
122 return false;
126 bool PageDescriptor::SetState (const State eState, const bool bNewStateValue)
128 bool bModified (false);
129 switch (eState)
131 case ST_Visible:
132 bModified = (bNewStateValue!=mbIsVisible);
133 if (bModified)
134 mbIsVisible = bNewStateValue;
135 break;
137 case ST_Selected:
138 bModified = (bNewStateValue!=mbIsSelected);
139 if (bModified)
140 mbIsSelected = bNewStateValue;
141 break;
143 case ST_WasSelected:
144 bModified = (bNewStateValue!=mbWasSelected);
145 if (bModified)
146 mbWasSelected = bNewStateValue;
147 break;
149 case ST_Focused:
150 bModified = (bNewStateValue!=mbIsFocused);
151 if (bModified)
152 mbIsFocused = bNewStateValue;
153 break;
155 case ST_MouseOver:
156 bModified = (bNewStateValue!=mbIsMouseOver);
157 if (bModified)
158 mbIsMouseOver = bNewStateValue;
159 break;
161 case ST_Current:
162 bModified = (bNewStateValue!=mbIsCurrent);
163 if (bModified)
164 mbIsCurrent = bNewStateValue;
165 break;
167 case ST_Excluded:
168 // This is a state of the page and has to be handled differently
169 // from the view-only states.
170 if (mpPage != nullptr)
171 if (bNewStateValue != mpPage->IsExcluded())
173 mpPage->SetExcluded(bNewStateValue);
174 bModified = true;
176 break;
179 return bModified;
182 bool PageDescriptor::GetCoreSelection()
184 if (mpPage!=nullptr && mpPage->IsSelected() != mbIsSelected)
185 return SetState(ST_Selected, !mbIsSelected);
186 else
187 return false;
190 void PageDescriptor::SetCoreSelection()
192 if (mpPage != nullptr)
193 if (HasState(ST_Selected))
194 mpPage->SetSelected(true);
195 else
196 mpPage->SetSelected(false);
197 else
199 assert(mpPage!=nullptr);
203 ::tools::Rectangle PageDescriptor::GetBoundingBox() const
205 ::tools::Rectangle aBox (maBoundingBox);
206 const Point aOffset (maVisualState.GetLocationOffset());
207 aBox.Move(aOffset.X(), aOffset.Y());
208 return aBox;
211 Point PageDescriptor::GetLocation (const bool bIgnoreOffset) const
213 if (bIgnoreOffset)
214 return maBoundingBox.TopLeft();
215 else
216 return maBoundingBox.TopLeft() + maVisualState.GetLocationOffset();
219 void PageDescriptor::SetBoundingBox (const ::tools::Rectangle& rBoundingBox)
221 maBoundingBox = rBoundingBox;
224 } // end of namespace ::sd::slidesorter::model
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */