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 FocusMoveDirection
61 /** Move the focus from the currently focused page to one that is
62 displayed adjacent to it, either vertically or horizontally.
64 Direction in which to move the focus. Wrap around is done
65 differently when moving vertically or horizontally. Vertical
66 wrap around takes place in the same column, i.e. when you are
67 in the top row and move up you come out in the bottom row in the
68 same column. Horizontal wrap around moves to the next
69 (FMD_RIGHT) or previous (FMD_LEFT) page. Moving to the right
70 from the last page goes to the first page and vice versa.
71 When FMD_NONE is given, the current page index is checked for
72 being valid. If it is not, then it is set to the nearest valid
75 void MoveFocus (FocusMoveDirection eDirection
);
77 /** Show the focus indicator of the current slide.
79 When <TRUE/> (the default) then the view is scrolled so that the
80 focus rectangle lies inside its visible area.
82 void ShowFocus (const bool bScrollToFocus
= true);
84 /** Hide the focus indicator.
88 /** Toggle the focused state of the current slide.
90 Returns the focused state of the focus page after the call.
94 /** Return whether the window managed by the called focus manager has
95 the input focus of the application.
97 bool HasFocus() const;
99 /** Return the descriptor of the page that currently has the focus.
101 When there is no page that currently has the focus then NULL is
104 model::SharedPageDescriptor
GetFocusedPageDescriptor() const;
106 /** Return the index of the page that currently has the focus as it is
107 accepted by the slide sorter model.
109 When there is no page that currently has the focus then -1 is
112 sal_Int32
GetFocusedPageIndex() const { return mnPageIndex
;}
114 /** Set the focused page to the one described by the given page
115 descriptor. The visibility of the focus indicator is not modified.
117 One of the page descriptors that are currently managed by the
120 void SetFocusedPage (const model::SharedPageDescriptor
& rDescriptor
);
122 /** Set the focused page to the one described by the given page
123 index. The visibility of the focus indicator is not modified.
125 A valid page index that is understood by the SlideSorterModel.
127 void SetFocusedPage (sal_Int32 nPageIndex
);
129 void SetFocusedPageToCurrentPage();
131 /** Return <TRUE/> when the focus inidcator is currently shown. A
132 prerequisite is that the window managed by this focus manager has
133 the input focus as indicated by a <TRUE/> return value of
134 HasFocus(). It is not necessary that the focus indicator is
135 visible. It may have been scrolled outside the visible area.
137 bool IsFocusShowing() const;
139 /** Add a listener that is called when the focus is shown or hidden or
140 set to another page object.
142 When this method is called multiple times for the same listener
143 the second and all following calls are ignored. Each listener
146 void AddFocusChangeListener (const Link
<>& rListener
);
148 /** Remove a focus change listener.
150 It is save to pass a listener that was not added are has been
151 removed previously. Such calls are ignored.
153 void RemoveFocusChangeListener (const Link
<>& rListener
);
155 /** Create an instance of this class to temporarily hide the focus
156 indicator. It is restored to its former visibility state when the
157 FocusHider is destroyed.
162 FocusHider (FocusManager
&);
166 FocusManager
& mrManager
;
170 SlideSorter
& mrSlideSorter
;
172 /** Index of the page that may be focused. It is -1 when the model
175 sal_Int32 mnPageIndex
;
177 /** This flag indicates whether the page pointed to by mpFocusDescriptor
180 bool mbPageIsFocused
;
182 ::std::vector
<Link
<>> maFocusChangeListeners
;
184 /** When vertical wrap is active then pressing UP in the top row moves
185 the focus to the bottom row, DOWN in the bottom row moves the focus
188 bool mbIsVerticalWrapActive
;
190 /** Reset the focus state of the given descriptor and request a repaint
191 so that the focus indicator is hidden.
193 When NULL is given then the call is ignored.
195 void HideFocusIndicator (const model::SharedPageDescriptor
& rpDescriptor
);
197 /** Set the focus state of the given descriptor, scroll it into the
198 visible area and request a repaint so that the focus indicator is
201 When NULL is given then the call is ignored.
202 @param bScrollToFocus
203 When <TRUE/> (the default) then the view is scrolled so that the
204 focus rectangle lies inside its visible area.
206 void ShowFocusIndicator (
207 const model::SharedPageDescriptor
& rpDescriptor
,
208 const bool bScrollToFocus
);
210 /** Call all currently registered listeners that a focus change has
211 happened. The focus may be hidden or shown or moved from one page
214 void NotifyFocusChangeListeners() const;
217 } } } // end of namespace ::sd::slidesorter::controller
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */