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 #include <vcl/dockwin.hxx>
21 #include <vcl/toolkit/floatwin.hxx>
22 #include <vcl/taskpanelist.hxx>
25 #include "menubarwindow.hxx"
31 Point
ImplTaskPaneListGetPos( const vcl::Window
*w
)
34 if( w
->IsDockingWindow() )
36 pos
= static_cast<const DockingWindow
*>(w
)->GetPosPixel();
37 vcl::Window
*pF
= static_cast<const DockingWindow
*>(w
)->GetFloatingWindow();
39 pos
= pF
->OutputToAbsoluteScreenPixel( pF
->ScreenToOutputPixel( pos
) );
41 pos
= w
->OutputToAbsoluteScreenPixel( pos
);
44 pos
= w
->OutputToAbsoluteScreenPixel( w
->GetPosPixel() );
49 // compares window pos left-to-right
52 bool operator()( const vcl::Window
* w1
, const vcl::Window
* w2
) const
54 Point
pos1(ImplTaskPaneListGetPos( w1
));
55 Point
pos2(ImplTaskPaneListGetPos( w2
));
57 if( pos1
.X() == pos2
.X() )
58 return ( pos1
.Y() < pos2
.Y() );
60 return ( pos1
.X() < pos2
.X() );
66 static void ImplTaskPaneListGrabFocus( vcl::Window
*pWindow
, bool bForward
)
68 // put focus in child of floating windows which is typically a toolbar
69 // that can deal with the focus
70 if( pWindow
->ImplIsFloatingWindow() && pWindow
->GetWindow( GetWindowType::FirstChild
) )
71 pWindow
= pWindow
->GetWindow( GetWindowType::FirstChild
);
72 pWindow
->ImplGrabFocus( GetFocusFlags::F6
| (bForward
? GetFocusFlags::Forward
: GetFocusFlags::Backward
));
75 TaskPaneList::TaskPaneList()
79 TaskPaneList::~TaskPaneList()
83 void TaskPaneList::AddWindow( vcl::Window
*pWindow
)
88 auto insertionPos
= dynamic_cast<MenuBarWindow
*>(pWindow
) ? mTaskPanes
.begin() : mTaskPanes
.end();
89 for ( auto p
= mTaskPanes
.begin(); p
!= mTaskPanes
.end(); ++p
)
95 // If the new window is the child of an existing pane window, or vice versa,
96 // ensure that in our pane list, *first* the child window appears, *then*
97 // the ancestor window.
98 // This is necessary for HandleKeyEvent: There, the list is traveled from the
99 // beginning, until the first window is found which has the ChildPathFocus. Now
100 // if this would be the ancestor window of another pane window, this would fudge
102 if ( pWindow
->IsWindowOrChild( *p
) )
104 insertionPos
= p
+ 1;
107 if ( (*p
)->IsWindowOrChild( pWindow
) )
114 mTaskPanes
.insert( insertionPos
, pWindow
);
115 pWindow
->ImplIsInTaskPaneList( true );
118 void TaskPaneList::RemoveWindow( vcl::Window
*pWindow
)
120 auto p
= ::std::find( mTaskPanes
.begin(), mTaskPanes
.end(), VclPtr
<vcl::Window
>(pWindow
) );
121 if( p
!= mTaskPanes
.end() )
123 mTaskPanes
.erase( p
);
124 pWindow
->ImplIsInTaskPaneList( false );
128 bool TaskPaneList::IsInList( vcl::Window
*pWindow
)
130 auto p
= ::std::find( mTaskPanes
.begin(), mTaskPanes
.end(), VclPtr
<vcl::Window
>(pWindow
) );
131 return p
!= mTaskPanes
.end();
134 bool TaskPaneList::IsCycleKey(const vcl::KeyCode
& rKeyCode
)
136 return rKeyCode
.GetCode() == KEY_F6
&& !rKeyCode
.IsMod2(); // F6
139 bool TaskPaneList::HandleKeyEvent(const KeyEvent
& rKeyEvent
)
142 // F6 cycles through everything and works always
145 // The old design was the following one:
146 // < Ctrl-TAB cycles through Menubar, Toolbars and Floatingwindows only and is
147 // < only active if one of those items has the focus
149 // Since the design of Ctrl-Tab looks to be inconsistent ( non-modal dialogs are not reachable
150 // and the shortcut conflicts with tab-control shortcut ), it is no more supported
151 vcl::KeyCode aKeyCode
= rKeyEvent
.GetKeyCode();
152 bool bForward
= !aKeyCode
.IsShift();
153 if (TaskPaneList::IsCycleKey(aKeyCode
))
155 bool bSplitterOnly
= aKeyCode
.IsMod1() && aKeyCode
.IsShift();
157 // is the focus in the list ?
158 auto p
= std::find_if(mTaskPanes
.begin(), mTaskPanes
.end(),
159 [](const VclPtr
<vcl::Window
>& rWinPtr
) { return rWinPtr
->HasChildPathFocus( true ); });
160 if( p
!= mTaskPanes
.end() )
162 vcl::Window
*pWin
= p
->get();
164 // Ctrl-F6 goes directly to the document
165 if( !pWin
->IsDialog() && aKeyCode
.IsMod1() && !aKeyCode
.IsShift() )
167 pWin
->ImplGrabFocusToDocument( GetFocusFlags::F6
);
171 // activate next task pane
172 vcl::Window
*pNextWin
= nullptr;
175 pNextWin
= FindNextSplitter( *p
);
177 pNextWin
= FindNextFloat( *p
, bForward
);
179 if( pNextWin
!= pWin
)
181 ImplGetSVData()->mpWinData
->mbNoSaveFocus
= true;
182 ImplTaskPaneListGrabFocus( pNextWin
, bForward
);
183 ImplGetSVData()->mpWinData
->mbNoSaveFocus
= false;
187 // forward key if no splitter found
191 // we did not find another taskpane, so
192 // put focus back into document
193 pWin
->ImplGrabFocusToDocument( GetFocusFlags::F6
| (bForward
? GetFocusFlags::Forward
: GetFocusFlags::Backward
));
199 // the focus is not in the list: activate first float if F6 was pressed
202 pWin
= FindNextSplitter( nullptr );
204 pWin
= FindNextFloat( nullptr, bForward
);
207 ImplTaskPaneListGrabFocus( pWin
, bForward
);
215 // returns next splitter
216 vcl::Window
* TaskPaneList::FindNextSplitter( vcl::Window
*pWindow
)
218 ::std::stable_sort( mTaskPanes
.begin(), mTaskPanes
.end(), LTRSort() );
220 auto p
= mTaskPanes
.begin();
222 p
= std::find(mTaskPanes
.begin(), mTaskPanes
.end(), pWindow
);
224 if( p
!= mTaskPanes
.end() )
226 unsigned n
= mTaskPanes
.size();
229 if( pWindow
) // increment before test
231 if( p
== mTaskPanes
.end() )
232 p
= mTaskPanes
.begin();
233 if( (*p
)->ImplIsSplitter() && (*p
)->IsReallyVisible() && !(*p
)->IsDialog() && (*p
)->GetParent()->HasChildPathFocus() )
235 pWindow
= (*p
).get();
238 if( !pWindow
) // increment after test, otherwise first element is skipped
246 // returns first valid item (regardless of type) if pWindow==0, otherwise returns next valid float
247 vcl::Window
* TaskPaneList::FindNextFloat( vcl::Window
*pWindow
, bool bForward
)
249 ::std::stable_sort( mTaskPanes
.begin(), mTaskPanes
.end(), LTRSort() );
252 ::std::reverse( mTaskPanes
.begin(), mTaskPanes
.end() );
254 auto p
= mTaskPanes
.begin();
256 p
= std::find(mTaskPanes
.begin(), mTaskPanes
.end(), pWindow
);
258 while( p
!= mTaskPanes
.end() )
260 if( pWindow
) // increment before test
262 if( p
== mTaskPanes
.end() )
263 break; // do not wrap, send focus back to document at end of list
264 /* #i83908# do not use the menubar if it is native and invisible
267 bool bSkip
= false; // used to skip infobar when it has no children
268 if( (*p
)->GetType() == WindowType::WINDOW
&& (*p
)->GetChildCount() == 0 )
271 if( !bSkip
&& (*p
)->IsReallyVisible() && !(*p
)->ImplIsSplitter() &&
272 ( (*p
)->GetType() != WindowType::MENUBARWINDOW
|| static_cast<MenuBarWindow
*>(p
->get())->CanGetFocus() ) )
274 pWindow
= (*p
).get();
277 if( !pWindow
) // increment after test, otherwise first element is skipped
282 ::std::reverse( mTaskPanes
.begin(), mTaskPanes
.end() );
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */