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 <tools/rcid.h>
22 #include <vcl/dockwin.hxx>
23 #include <vcl/taskpanelist.hxx>
26 #include "menubarwindow.hxx"
33 Point
ImplTaskPaneListGetPos( const vcl::Window
*w
)
36 if( w
->IsDockingWindow() )
38 pos
= static_cast<const DockingWindow
*>(w
)->GetPosPixel();
39 vcl::Window
*pF
= static_cast<const DockingWindow
*>(w
)->GetFloatingWindow();
41 pos
= pF
->OutputToAbsoluteScreenPixel( pF
->ScreenToOutputPixel( pos
) );
43 pos
= w
->OutputToAbsoluteScreenPixel( pos
);
46 pos
= w
->OutputToAbsoluteScreenPixel( w
->GetPosPixel() );
53 // compares window pos left-to-right
54 struct LTRSort
: public ::std::binary_function
< const vcl::Window
*, const vcl::Window
*, bool >
56 bool operator()( const vcl::Window
* w1
, const vcl::Window
* w2
) const
58 Point
pos1(ImplTaskPaneListGetPos( w1
));
59 Point
pos2(ImplTaskPaneListGetPos( w2
));
61 if( pos1
.X() == pos2
.X() )
62 return ( pos1
.Y() < pos2
.Y() );
64 return ( pos1
.X() < pos2
.X() );
67 struct LTRSortBackward
: public ::std::binary_function
< const vcl::Window
*, const vcl::Window
*, bool >
69 bool operator()( const vcl::Window
* w2
, const vcl::Window
* w1
) const
71 Point
pos1(ImplTaskPaneListGetPos( w1
));
72 Point
pos2(ImplTaskPaneListGetPos( w2
));
74 if( pos1
.X() == pos2
.X() )
75 return ( pos1
.Y() < pos2
.Y() );
77 return ( pos1
.X() < pos2
.X() );
81 static void ImplTaskPaneListGrabFocus( vcl::Window
*pWindow
, bool bForward
)
83 // put focus in child of floating windows which is typically a toolbar
84 // that can deal with the focus
85 if( pWindow
->ImplIsFloatingWindow() && pWindow
->GetWindow( GetWindowType::FirstChild
) )
86 pWindow
= pWindow
->GetWindow( GetWindowType::FirstChild
);
87 pWindow
->ImplGrabFocus( GetFocusFlags::F6
| (bForward
? GetFocusFlags::Forward
: GetFocusFlags::Backward
));
90 TaskPaneList::TaskPaneList()
94 TaskPaneList::~TaskPaneList()
98 void TaskPaneList::AddWindow( vcl::Window
*pWindow
)
102 auto insertionPos
= dynamic_cast<MenuBarWindow
*>(pWindow
) ? mTaskPanes
.begin() : mTaskPanes
.end();
103 for ( auto p
= mTaskPanes
.begin(); p
!= mTaskPanes
.end(); ++p
)
109 // If the new window is the child of an existing pane window, or vice versa,
110 // ensure that in our pane list, *first* the child window appears, *then*
111 // the ancestor window.
112 // This is necessary for HandleKeyEvent: There, the list is traveled from the
113 // beginning, until the first window is found which has the ChildPathFocus. Now
114 // if this would be the ancestor window of another pane window, this would fudge
116 if ( pWindow
->IsWindowOrChild( *p
) )
118 insertionPos
= p
+ 1;
121 if ( (*p
)->IsWindowOrChild( pWindow
) )
128 mTaskPanes
.insert( insertionPos
, pWindow
);
129 pWindow
->ImplIsInTaskPaneList( true );
133 void TaskPaneList::RemoveWindow( vcl::Window
*pWindow
)
135 auto p
= ::std::find( mTaskPanes
.begin(), mTaskPanes
.end(), VclPtr
<vcl::Window
>(pWindow
) );
136 if( p
!= mTaskPanes
.end() )
138 mTaskPanes
.erase( p
);
139 pWindow
->ImplIsInTaskPaneList( false );
143 bool TaskPaneList::IsInList( vcl::Window
*pWindow
)
145 auto p
= ::std::find( mTaskPanes
.begin(), mTaskPanes
.end(), VclPtr
<vcl::Window
>(pWindow
) );
146 if( p
!= mTaskPanes
.end() )
152 bool TaskPaneList::IsCycleKey(const vcl::KeyCode
& rKeyCode
)
154 return rKeyCode
.GetCode() == KEY_F6
&& !rKeyCode
.IsMod2(); // F6
157 bool TaskPaneList::HandleKeyEvent(const KeyEvent
& rKeyEvent
)
160 // F6 cycles through everything and works always
163 // The old design was the following one:
164 // < Ctrl-TAB cycles through Menubar, Toolbars and Floatingwindows only and is
165 // < only active if one of those items has the focus
167 // Since the design of Ctrl-Tab looks to be inconsistent ( non-modal dialogs are not reachable
168 // and the shortcut conflicts with tab-control shortcut ), it is no more supported
169 vcl::KeyCode aKeyCode
= rKeyEvent
.GetKeyCode();
170 bool bForward
= !aKeyCode
.IsShift();
171 if (TaskPaneList::IsCycleKey(aKeyCode
))
173 bool bSplitterOnly
= aKeyCode
.IsMod1() && aKeyCode
.IsShift();
175 // is the focus in the list ?
176 auto p
= mTaskPanes
.begin();
177 while( p
!= mTaskPanes
.end() )
179 vcl::Window
*pWin
= p
->get();
180 if( pWin
->HasChildPathFocus( true ) )
182 // Ctrl-F6 goes directly to the document
183 if( !pWin
->IsDialog() && aKeyCode
.IsMod1() && !aKeyCode
.IsShift() )
185 pWin
->ImplGrabFocusToDocument( GetFocusFlags::F6
);
189 // activate next task pane
190 vcl::Window
*pNextWin
= nullptr;
193 pNextWin
= FindNextSplitter( *p
);
195 pNextWin
= FindNextFloat( *p
, bForward
);
197 if( pNextWin
!= pWin
)
199 ImplGetSVData()->maWinData
.mbNoSaveFocus
= true;
200 ImplTaskPaneListGrabFocus( pNextWin
, bForward
);
201 ImplGetSVData()->maWinData
.mbNoSaveFocus
= false;
205 // forward key if no splitter found
209 // we did not find another taskpane, so
210 // put focus back into document
211 pWin
->ImplGrabFocusToDocument( GetFocusFlags::F6
| (bForward
? GetFocusFlags::Forward
: GetFocusFlags::Backward
));
220 // the focus is not in the list: activate first float if F6 was pressed
223 pWin
= FindNextSplitter( nullptr );
225 pWin
= FindNextFloat( nullptr, bForward
);
228 ImplTaskPaneListGrabFocus( pWin
, bForward
);
236 // returns next splitter
237 vcl::Window
* TaskPaneList::FindNextSplitter( vcl::Window
*pWindow
)
239 ::std::stable_sort( mTaskPanes
.begin(), mTaskPanes
.end(), LTRSort() );
241 auto p
= mTaskPanes
.begin();
242 while( p
!= mTaskPanes
.end() )
244 if( !pWindow
|| *p
== pWindow
)
246 unsigned n
= mTaskPanes
.size();
249 if( pWindow
) // increment before test
251 if( p
== mTaskPanes
.end() )
252 p
= mTaskPanes
.begin();
253 if( (*p
)->ImplIsSplitter() && (*p
)->IsReallyVisible() && !(*p
)->IsDialog() && (*p
)->GetParent()->HasChildPathFocus() )
255 pWindow
= (*p
).get();
258 if( !pWindow
) // increment after test, otherwise first element is skipped
270 // returns first valid item (regardless of type) if pWindow==0, otherwise returns next valid float
271 vcl::Window
* TaskPaneList::FindNextFloat( vcl::Window
*pWindow
, bool bForward
)
274 ::std::stable_sort( mTaskPanes
.begin(), mTaskPanes
.end(), LTRSort() );
276 ::std::stable_sort( mTaskPanes
.begin(), mTaskPanes
.end(), LTRSortBackward() );
278 auto p
= mTaskPanes
.begin();
279 while( p
!= mTaskPanes
.end() )
281 if( !pWindow
|| *p
== pWindow
)
283 while( p
!= mTaskPanes
.end() )
285 if( pWindow
) // increment before test
287 if( p
== mTaskPanes
.end() )
288 break; // do not wrap, send focus back to document at end of list
289 /* #i83908# do not use the menubar if it is native and invisible
291 if( (*p
)->IsReallyVisible() && !(*p
)->ImplIsSplitter() &&
292 ( (*p
)->GetType() != WINDOW_MENUBARWINDOW
|| static_cast<MenuBarWindow
*>(p
->get())->CanGetFocus() ) )
294 pWindow
= (*p
).get();
297 if( !pWindow
) // increment after test, otherwise first element is skipped
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */