LibreOffice Module sd (master) 1
SlsFocusManager.cxx
Go to the documentation of this file.
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
21
22#include <SlideSorter.hxx>
29#include <view/SlsLayouter.hxx>
30#include <osl/diagnose.h>
31
32#include <Window.hxx>
33#include <sdpage.hxx>
34
36
38 : mrSlideSorter(rSlideSorter),
39 mnPageIndex(0),
40 mbPageIsFocused(false)
41{
43 mnPageIndex = 0;
44}
45
47{
48}
49
51{
52 if (!(mnPageIndex >= 0 && mbPageIsFocused))
53 return;
54
56
57 const sal_Int32 nColumnCount (mrSlideSorter.GetView().GetLayouter().GetColumnCount());
58 const sal_Int32 nPageCount (mrSlideSorter.GetModel().GetPageCount());
59 switch (eDirection)
60 {
62 if (mnPageIndex > 0)
63 mnPageIndex -= 1;
64 break;
65
67 if (mnPageIndex < nPageCount-1)
68 mnPageIndex += 1;
69 break;
70
72 {
73 const sal_Int32 nCandidate (mnPageIndex - nColumnCount);
74 if (nCandidate >= 0)
75 {
76 // Move the focus the previous row.
77 mnPageIndex = nCandidate;
78 }
79 }
80 break;
81
83 {
84 const sal_Int32 nCandidate (mnPageIndex + nColumnCount);
85 if (nCandidate < nPageCount)
86 {
87 // Move the focus to the next row.
88 mnPageIndex = nCandidate;
89 }
90 }
91 break;
92 }
93
94 if (mnPageIndex < 0)
95 {
96 OSL_ASSERT(mnPageIndex>=0);
97 mnPageIndex = 0;
98 }
99 else if (mnPageIndex >= nPageCount)
100 {
101 OSL_ASSERT(mnPageIndex<nPageCount);
102 mnPageIndex = nPageCount - 1;
103 }
104
105 if (mbPageIsFocused)
106 {
108 }
109}
110
111void FocusManager::ShowFocus (const bool bScrollToFocus)
112{
113 mbPageIsFocused = true;
115}
116
118{
119 mbPageIsFocused = false;
121}
122
124{
125 if (mnPageIndex >= 0)
126 {
127 if (mbPageIsFocused)
128 HideFocus ();
129 else
130 ShowFocus ();
131 }
132 return mbPageIsFocused;
133}
134
136{
137 return mrSlideSorter.GetContentWindow()->HasFocus();
138}
139
141{
143}
144
146{
147 if (rpDescriptor)
148 {
149 FocusHider aFocusHider (*this);
150 mnPageIndex = (rpDescriptor->GetPage()->GetPageNum()-1)/2;
151 return true;
152 }
153 return false;
154}
155
156void FocusManager::SetFocusedPage (sal_Int32 nPageIndex)
157{
158 FocusHider aFocusHider (*this);
159 mnPageIndex = nPageIndex;
160}
161
163{
165}
166
168{
169 return HasFocus() && mbPageIsFocused;
170}
171
173{
174 if (rpDescriptor)
175 {
177
178 // Hide focus should also fire the focus event, Currently, only accessibility add the focus listener
180 }
181}
182
184 const model::SharedPageDescriptor& rpDescriptor,
185 const bool bScrollToFocus)
186{
187 if (!rpDescriptor)
188 return;
189
191
192 if (bScrollToFocus)
193 {
194 // Scroll the focused page object into the visible area and repaint
195 // it, so that the focus indicator becomes visible.
197 }
198 mrSlideSorter.GetView().RequestRepaint(rpDescriptor);
199
201}
202
204{
205 if (::std::find (maFocusChangeListeners.begin(), maFocusChangeListeners.end(), rListener)
206 == maFocusChangeListeners.end())
207 {
208 maFocusChangeListeners.push_back (rListener);
209 }
210}
211
213{
215 ::std::find (maFocusChangeListeners.begin(), maFocusChangeListeners.end(), rListener));
216}
217
219{
220 // Create a copy of the listener list to be safe when that is modified.
221 ::std::vector<Link<LinkParamNone*,void>> aListeners (maFocusChangeListeners);
222
223 // Tell the selection change listeners that the selection has changed.
224 for (const auto& rListener : aListeners)
225 {
226 rListener.Call(nullptr);
227 }
228}
229
231: mbFocusVisible(rManager.IsFocusShowing())
232, mrManager(rManager)
233{
235}
236
238{
239 if (mbFocusVisible)
240 mrManager.ShowFocus();
241}
242
243} // end of namespace ::sd::slidesorter::controller
244
245/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SlideSorter & mrSlideSorter
Show previews for all the slides in a document and allow the user to insert or delete slides and modi...
Definition: SlideSorter.hxx:62
SD_DLLPUBLIC controller::SlideSorterController & GetController() const
const VclPtr< sd::Window > & GetContentWindow() const
Return the content window.
Definition: SlideSorter.hxx:99
model::SlideSorterModel & GetModel() const
view::SlideSorterView & GetView() const
Create an instance of this class to temporarily hide the focus indicator.
This class manages the focus of the slide sorter.
void MoveFocus(FocusMoveDirection eDirection)
Move the focus from the currently focused page to one that is displayed adjacent to it,...
void NotifyFocusChangeListeners() const
Call all currently registered listeners that a focus change has happened.
bool ToggleFocus()
Toggle the focused state of the current slide.
model::SharedPageDescriptor GetFocusedPageDescriptor() const
Return the descriptor of the page that currently has the focus.
::std::vector< Link< LinkParamNone *, void > > maFocusChangeListeners
void RemoveFocusChangeListener(const Link< LinkParamNone *, void > &rListener)
Remove a focus change listener.
void HideFocus()
Hide the focus indicator.
bool mbPageIsFocused
This flag indicates whether the page pointed to by mpFocusDescriptor has the focus.
bool SetFocusedPage(const model::SharedPageDescriptor &rDescriptor)
Set the focused page to the one described by the given page descriptor.
void ShowFocus(const bool bScrollToFocus=true)
Show the focus indicator of the current slide.
FocusManager(SlideSorter &rSlideSorter)
Create a new focus manager that operates on the pages of the model associated with the given controll...
void HideFocusIndicator(const model::SharedPageDescriptor &rpDescriptor)
Reset the focus state of the given descriptor and request a repaint so that the focus indicator is hi...
void AddFocusChangeListener(const Link< LinkParamNone *, void > &rListener)
Add a listener that is called when the focus is shown or hidden or set to another page object.
void ShowFocusIndicator(const model::SharedPageDescriptor &rpDescriptor, const bool bScrollToFocus)
Set the focus state of the given descriptor, scroll it into the visible area and request a repaint so...
bool IsFocusShowing() const
Return <TRUE> when the focus indicator is currently shown.
sal_Int32 mnPageIndex
Index of the page that may be focused.
bool HasFocus() const
Return whether the window managed by the called focus manager has the input focus of the application.
bool SetFocusedPageFromCurrentPage()
Set the focused page to the one that is the current slide of the Slide Manager.
std::shared_ptr< CurrentSlideManager > const & GetCurrentSlideManager() const
void RequestVisible(const model::SharedPageDescriptor &rpDescriptor, const bool bForce=false)
Request to make the specified page object visible.
sal_Int32 GetPageCount() const
Return the number of slides in the document regardless of whether they are visible or not or whether ...
SharedPageDescriptor GetPageDescriptor(const sal_Int32 nPageIndex, const bool bCreate=true) const
Return a page descriptor for the page with the specified index.
sal_Int32 GetColumnCount() const
Return the number of columns.
bool SetState(const model::SharedPageDescriptor &rpDescriptor, const model::PageDescriptor::State eState, const bool bStateValue)
Listeners aListeners
std::shared_ptr< PageDescriptor > SharedPageDescriptor