Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "controller/SlsFocusManager.hxx"
30 : :
31 : : #include "SlideSorter.hxx"
32 : : #include "PaneDockingWindow.hxx"
33 : : #include "controller/SlideSorterController.hxx"
34 : : #include "controller/SlsCurrentSlideManager.hxx"
35 : : #include "controller/SlsVisibleAreaManager.hxx"
36 : : #include "model/SlideSorterModel.hxx"
37 : : #include "model/SlsPageDescriptor.hxx"
38 : : #include "view/SlideSorterView.hxx"
39 : : #include "view/SlsLayouter.hxx"
40 : : #include <vcl/toolbox.hxx>
41 : :
42 : : #include "Window.hxx"
43 : : #include "sdpage.hxx"
44 : :
45 : : namespace sd { namespace slidesorter { namespace controller {
46 : :
47 : 130 : FocusManager::FocusManager (SlideSorter& rSlideSorter)
48 : : : mrSlideSorter(rSlideSorter),
49 : : mnPageIndex(0),
50 : : mbPageIsFocused(false),
51 : 130 : mbIsVerticalWrapActive(false)
52 : : {
53 [ + - ][ - + ]: 130 : if (mrSlideSorter.GetModel().GetPageCount() > 0)
[ + - ]
54 : 0 : mnPageIndex = 0;
55 : 130 : }
56 : :
57 : :
58 : :
59 : :
60 : 130 : FocusManager::~FocusManager (void)
61 : : {
62 : 130 : }
63 : :
64 : :
65 : :
66 : :
67 : 0 : void FocusManager::MoveFocus (FocusMoveDirection eDirection)
68 : : {
69 [ # # ][ # # ]: 0 : if (mnPageIndex >= 0 && mbPageIsFocused)
70 : : {
71 [ # # ]: 0 : HideFocusIndicator (GetFocusedPageDescriptor());
72 : :
73 : 0 : const sal_Int32 nColumnCount (mrSlideSorter.GetView().GetLayouter().GetColumnCount());
74 : 0 : const sal_Int32 nPageCount (mrSlideSorter.GetModel().GetPageCount());
75 [ # # # # : 0 : switch (eDirection)
# # ]
76 : : {
77 : : case FMD_NONE:
78 : : // Nothing to be done.
79 : 0 : break;
80 : :
81 : : case FMD_LEFT:
82 [ # # ]: 0 : if (mnPageIndex > 0)
83 : 0 : mnPageIndex -= 1;
84 [ # # ]: 0 : else if (mbIsVerticalWrapActive)
85 : 0 : mnPageIndex = nPageCount-1;
86 : 0 : break;
87 : :
88 : : case FMD_RIGHT:
89 [ # # ]: 0 : if (mnPageIndex < nPageCount-1)
90 : 0 : mnPageIndex += 1;
91 [ # # ]: 0 : else if (mbIsVerticalWrapActive)
92 : 0 : mnPageIndex = 0;
93 : 0 : break;
94 : :
95 : : case FMD_UP:
96 : : {
97 : 0 : const sal_Int32 nCandidate (mnPageIndex - nColumnCount);
98 [ # # ]: 0 : if (nCandidate < 0)
99 : : {
100 [ # # ]: 0 : if (mbIsVerticalWrapActive)
101 : : {
102 : : // Wrap arround to the bottom row or the one above
103 : : // and go to the correct column.
104 : 0 : const sal_Int32 nLastIndex (nPageCount-1);
105 : 0 : const sal_Int32 nLastColumn (nLastIndex % nColumnCount);
106 : 0 : const sal_Int32 nCurrentColumn (mnPageIndex%nColumnCount);
107 [ # # ]: 0 : if (nLastColumn >= nCurrentColumn)
108 : : {
109 : : // The last row contains the current column.
110 : 0 : mnPageIndex = nLastIndex - (nLastColumn-nCurrentColumn);
111 : : }
112 : : else
113 : : {
114 : : // Only the second to last row contains the current column.
115 : : mnPageIndex = nLastIndex - nLastColumn
116 : : - nColumnCount
117 : 0 : + nCurrentColumn;
118 : : }
119 : : }
120 : : }
121 : : else
122 : : {
123 : : // Move the focus the previous row.
124 : 0 : mnPageIndex = nCandidate;
125 : : }
126 : : }
127 : 0 : break;
128 : :
129 : : case FMD_DOWN:
130 : : {
131 : 0 : const sal_Int32 nCandidate (mnPageIndex + nColumnCount);
132 [ # # ]: 0 : if (nCandidate >= nPageCount)
133 : : {
134 [ # # ]: 0 : if (mbIsVerticalWrapActive)
135 : : {
136 : : // Wrap arround to the correct column.
137 : 0 : mnPageIndex = mnPageIndex % nColumnCount;
138 : : }
139 : : else
140 : : {
141 : : // Do not move the focus.
142 : : }
143 : : }
144 : : else
145 : : {
146 : : // Move the focus to the next row.
147 : 0 : mnPageIndex = nCandidate;
148 : : }
149 : : }
150 : 0 : break;
151 : : }
152 : :
153 [ # # ]: 0 : if (mnPageIndex < 0)
154 : : {
155 : : OSL_ASSERT(mnPageIndex>=0);
156 : 0 : mnPageIndex = 0;
157 : : }
158 [ # # ]: 0 : else if (mnPageIndex >= nPageCount)
159 : : {
160 : : OSL_ASSERT(mnPageIndex<nPageCount);
161 : 0 : mnPageIndex = nPageCount - 1;
162 : : }
163 : :
164 [ # # ]: 0 : if (mbPageIsFocused)
165 : : {
166 [ # # ]: 0 : ShowFocusIndicator(GetFocusedPageDescriptor(), true);
167 : : }
168 : : }
169 : 0 : }
170 : :
171 : :
172 : :
173 : :
174 : 0 : void FocusManager::ShowFocus (const bool bScrollToFocus)
175 : : {
176 : 0 : mbPageIsFocused = true;
177 [ # # ]: 0 : ShowFocusIndicator(GetFocusedPageDescriptor(), bScrollToFocus);
178 : 0 : }
179 : :
180 : :
181 : :
182 : :
183 : 138 : void FocusManager::HideFocus (void)
184 : : {
185 : 138 : mbPageIsFocused = false;
186 [ + - ]: 138 : HideFocusIndicator(GetFocusedPageDescriptor());
187 : 138 : }
188 : :
189 : :
190 : :
191 : :
192 : 0 : bool FocusManager::ToggleFocus (void)
193 : : {
194 [ # # ]: 0 : if (mnPageIndex >= 0)
195 : : {
196 [ # # ]: 0 : if (mbPageIsFocused)
197 : 0 : HideFocus ();
198 : : else
199 : 0 : ShowFocus ();
200 : : }
201 : 0 : return mbPageIsFocused;
202 : : }
203 : :
204 : :
205 : :
206 : :
207 : 138 : bool FocusManager::HasFocus (void) const
208 : : {
209 [ + - ]: 138 : return mrSlideSorter.GetContentWindow()->HasFocus();
210 : : }
211 : :
212 : :
213 : :
214 : :
215 : 138 : model::SharedPageDescriptor FocusManager::GetFocusedPageDescriptor (void) const
216 : : {
217 : 138 : return mrSlideSorter.GetModel().GetPageDescriptor(mnPageIndex);
218 : : }
219 : :
220 : :
221 : :
222 : :
223 : 0 : sal_Int32 FocusManager::GetFocusedPageIndex (void) const
224 : : {
225 : 0 : return mnPageIndex;
226 : : }
227 : :
228 : :
229 : 138 : void FocusManager::SetFocusedPage (const model::SharedPageDescriptor& rpDescriptor)
230 : : {
231 [ + - ]: 138 : if (rpDescriptor.get() != NULL)
232 : : {
233 [ + - ]: 138 : FocusHider aFocusHider (*this);
234 [ + - ][ + - ]: 138 : mnPageIndex = (rpDescriptor->GetPage()->GetPageNum()-1)/2;
[ + - ]
235 : : }
236 : 138 : }
237 : :
238 : :
239 : :
240 : :
241 : 0 : void FocusManager::SetFocusedPage (sal_Int32 nPageIndex)
242 : : {
243 [ # # ]: 0 : FocusHider aFocusHider (*this);
244 [ # # ]: 0 : mnPageIndex = nPageIndex;
245 : 0 : }
246 : :
247 : :
248 : :
249 : :
250 : 0 : void FocusManager::SetFocusedPageToCurrentPage (void)
251 : : {
252 [ # # ][ # # ]: 0 : SetFocusedPage(mrSlideSorter.GetController().GetCurrentSlideManager()->GetCurrentSlide());
[ # # ]
253 : 0 : }
254 : :
255 : :
256 : :
257 : :
258 : 138 : bool FocusManager::IsFocusShowing (void) const
259 : : {
260 [ - + ][ # # ]: 138 : return HasFocus() && mbPageIsFocused;
261 : : }
262 : :
263 : :
264 : :
265 : :
266 : 138 : void FocusManager::HideFocusIndicator (const model::SharedPageDescriptor& rpDescriptor)
267 : : {
268 [ + - ]: 138 : if (rpDescriptor.get() != NULL)
269 : : {
270 : 138 : mrSlideSorter.GetView().SetState(rpDescriptor, model::PageDescriptor::ST_Focused, false);
271 : : }
272 : 138 : }
273 : :
274 : :
275 : :
276 : :
277 : 0 : void FocusManager::ShowFocusIndicator (
278 : : const model::SharedPageDescriptor& rpDescriptor,
279 : : const bool bScrollToFocus)
280 : : {
281 [ # # ]: 0 : if (rpDescriptor.get() != NULL)
282 : : {
283 : 0 : mrSlideSorter.GetView().SetState(rpDescriptor, model::PageDescriptor::ST_Focused, true);
284 : :
285 [ # # ]: 0 : if (bScrollToFocus)
286 : : {
287 : : // Scroll the focused page object into the visible area and repaint
288 : : // it, so that the focus indicator becomes visible.
289 : 0 : mrSlideSorter.GetController().GetVisibleAreaManager().RequestVisible(rpDescriptor,true);
290 : : }
291 : 0 : mrSlideSorter.GetView().RequestRepaint(rpDescriptor);
292 : :
293 : 0 : NotifyFocusChangeListeners();
294 : : }
295 : 0 : }
296 : :
297 : :
298 : :
299 : :
300 : 0 : void FocusManager::AddFocusChangeListener (const Link& rListener)
301 : : {
302 [ # # ][ # # ]: 0 : if (::std::find (maFocusChangeListeners.begin(), maFocusChangeListeners.end(), rListener)
303 [ # # ]: 0 : == maFocusChangeListeners.end())
304 : : {
305 : 0 : maFocusChangeListeners.push_back (rListener);
306 : : }
307 : 0 : }
308 : :
309 : :
310 : :
311 : :
312 : 0 : void FocusManager::RemoveFocusChangeListener (const Link& rListener)
313 : : {
314 : : maFocusChangeListeners.erase (
315 : 0 : ::std::find (maFocusChangeListeners.begin(), maFocusChangeListeners.end(), rListener));
316 : 0 : }
317 : :
318 : 0 : void FocusManager::NotifyFocusChangeListeners (void) const
319 : : {
320 : : // Create a copy of the listener list to be safe when that is modified.
321 [ # # ]: 0 : ::std::vector<Link> aListeners (maFocusChangeListeners);
322 : :
323 : : // Tell the slection change listeners that the selection has changed.
324 : 0 : ::std::vector<Link>::iterator iListener (aListeners.begin());
325 : 0 : ::std::vector<Link>::iterator iEnd (aListeners.end());
326 [ # # ][ # # ]: 0 : for (; iListener!=iEnd; ++iListener)
[ # # ]
327 : : {
328 [ # # ][ # # ]: 0 : iListener->Call(NULL);
329 : 0 : }
330 : 0 : }
331 : :
332 : :
333 : :
334 : :
335 : 138 : FocusManager::FocusHider::FocusHider (FocusManager& rManager)
336 : 138 : : mbFocusVisible(rManager.IsFocusShowing())
337 : 138 : , mrManager(rManager)
338 : : {
339 : 138 : mrManager.HideFocus();
340 : 138 : }
341 : :
342 : :
343 : :
344 : :
345 : 138 : FocusManager::FocusHider::~FocusHider (void)
346 : : {
347 [ - + ]: 138 : if (mbFocusVisible)
348 : 0 : mrManager.ShowFocus();
349 : 138 : }
350 : :
351 : : } } } // end of namespace ::sd::slidesorter::controller
352 : :
353 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|