1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_SD_SOURCE_UI_SLIDESORTER_INC_CONTROLLER_SLSFOCUSMANAGER_HXX
21 #define INCLUDED_SD_SOURCE_UI_SLIDESORTER_INC_CONTROLLER_SLSFOCUSMANAGER_HXX
23 #include <model/SlsSharedPageDescriptor.hxx>
25 #include <sal/types.h>
26 #include <tools/link.hxx>
29 namespace sd
{ namespace slidesorter
{
33 namespace sd
{ namespace slidesorter
{ namespace controller
{
35 /** This class manages the focus of the slide sorter. There is the focus
36 page which is or is not focused. Initialized to point to the first page
37 it can be set to other pages by using the MoveFocus() method. The
38 focused state of the focus page can be toggled with the ToggleFocus()
44 /** Create a new focus manager that operates on the pages of the model
45 associated with the given controller. The focus page is set to the
46 first page. Focused state is off.
48 FocusManager (SlideSorter
& rSlideSorter
);
52 enum class FocusMoveDirection
60 /** Move the focus from the currently focused page to one that is
61 displayed adjacent to it, either vertically or horizontally.
63 Direction in which to move the focus. Wrap around is done
64 differently when moving vertically or horizontally. Vertical
65 wrap around takes place in the same column, i.e. when you are
66 in the top row and move up you come out in the bottom row in the
67 same column. Horizontal wrap around moves to the next
68 (FocusMoveDirection::Right) or previous (FocusMoveDirection::Left) page. Moving to the right
69 from the last page goes to the first page and vice versa.
70 The current page index is set to the nearest valid
73 void MoveFocus (FocusMoveDirection eDirection
);
75 /** Show the focus indicator of the current slide.
77 When <TRUE/> (the default) then the view is scrolled so that the
78 focus rectangle lies inside its visible area.
80 void ShowFocus (const bool bScrollToFocus
= true);
82 /** Hide the focus indicator.
86 /** Toggle the focused state of the current slide.
88 Returns the focused state of the focus page after the call.
92 /** Return whether the window managed by the called focus manager has
93 the input focus of the application.
95 bool HasFocus() const;
97 /** Return the descriptor of the page that currently has the focus.
99 When there is no page that currently has the focus then NULL is
102 model::SharedPageDescriptor
GetFocusedPageDescriptor() const;
104 /** Return the index of the page that currently has the focus as it is
105 accepted by the slide sorter model.
107 When there is no page that currently has the focus then -1 is
110 sal_Int32
GetFocusedPageIndex() const { return mnPageIndex
;}
112 /** Set the focused page to the one described by the given page
113 descriptor. The visibility of the focus indicator is not modified.
115 One of the page descriptors that are currently managed by the
118 void SetFocusedPage (const model::SharedPageDescriptor
& rDescriptor
);
120 /** Set the focused page to the one described by the given page
121 index. The visibility of the focus indicator is not modified.
123 A valid page index that is understood by the SlideSorterModel.
125 void SetFocusedPage (sal_Int32 nPageIndex
);
127 void SetFocusedPageToCurrentPage();
129 /** Return <TRUE/> when the focus inidcator is currently shown. A
130 prerequisite is that the window managed by this focus manager has
131 the input focus as indicated by a <TRUE/> return value of
132 HasFocus(). It is not necessary that the focus indicator is
133 visible. It may have been scrolled outside the visible area.
135 bool IsFocusShowing() const;
137 /** Add a listener that is called when the focus is shown or hidden or
138 set to another page object.
140 When this method is called multiple times for the same listener
141 the second and all following calls are ignored. Each listener
144 void AddFocusChangeListener (const Link
<LinkParamNone
*,void>& rListener
);
146 /** Remove a focus change listener.
148 It is safe to pass a listener that was not added are has been
149 removed previously. Such calls are ignored.
151 void RemoveFocusChangeListener (const Link
<LinkParamNone
*,void>& rListener
);
153 /** Create an instance of this class to temporarily hide the focus
154 indicator. It is restored to its former visibility state when the
155 FocusHider is destroyed.
160 FocusHider (FocusManager
&);
161 ~FocusHider() COVERITY_NOEXCEPT_FALSE
;
163 bool const mbFocusVisible
;
164 FocusManager
& mrManager
;
168 SlideSorter
& mrSlideSorter
;
170 /** Index of the page that may be focused. It is -1 when the model
173 sal_Int32 mnPageIndex
;
175 /** This flag indicates whether the page pointed to by mpFocusDescriptor
178 bool mbPageIsFocused
;
180 ::std::vector
<Link
<LinkParamNone
*,void>> maFocusChangeListeners
;
182 /** Reset the focus state of the given descriptor and request a repaint
183 so that the focus indicator is hidden.
185 When NULL is given then the call is ignored.
187 void HideFocusIndicator (const model::SharedPageDescriptor
& rpDescriptor
);
189 /** Set the focus state of the given descriptor, scroll it into the
190 visible area and request a repaint so that the focus indicator is
193 When NULL is given then the call is ignored.
194 @param bScrollToFocus
195 When <TRUE/> (the default) then the view is scrolled so that the
196 focus rectangle lies inside its visible area.
198 void ShowFocusIndicator (
199 const model::SharedPageDescriptor
& rpDescriptor
,
200 const bool bScrollToFocus
);
202 /** Call all currently registered listeners that a focus change has
203 happened. The focus may be hidden or shown or moved from one page
206 void NotifyFocusChangeListeners() const;
209 } } } // end of namespace ::sd::slidesorter::controller
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */