LibreOffice Module vcl (master)  1
taskpanelist.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 
20 #include <vcl/dockwin.hxx>
21 #include <vcl/toolkit/floatwin.hxx>
22 #include <vcl/taskpanelist.hxx>
23 
24 #include <svdata.hxx>
25 #include "menubarwindow.hxx"
26 
27 #include <algorithm>
28 
29 namespace {
30 
31 Point ImplTaskPaneListGetPos( const vcl::Window *w )
32 {
33  Point pos;
34  if( w->IsDockingWindow() )
35  {
36  pos = static_cast<const DockingWindow*>(w)->GetPosPixel();
37  vcl::Window *pF = static_cast<const DockingWindow*>(w)->GetFloatingWindow();
38  if( pF )
39  pos = pF->OutputToAbsoluteScreenPixel( pF->ScreenToOutputPixel( pos ) );
40  else
41  pos = w->OutputToAbsoluteScreenPixel( pos );
42  }
43  else
45 
46  return pos;
47 }
48 
49 // compares window pos left-to-right
50 struct LTRSort
51 {
52  bool operator()( const vcl::Window* w1, const vcl::Window* w2 ) const
53  {
54  Point pos1(ImplTaskPaneListGetPos( w1 ));
55  Point pos2(ImplTaskPaneListGetPos( w2 ));
56 
57  if( pos1.X() == pos2.X() )
58  return ( pos1.Y() < pos2.Y() );
59  else
60  return ( pos1.X() < pos2.X() );
61  }
62 };
63 
64 }
65 
66 static void ImplTaskPaneListGrabFocus( vcl::Window *pWindow, bool bForward )
67 {
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 );
73 }
74 
76 {
77 }
78 
80 {
81 }
82 
84 {
85  if( !pWindow )
86  return;
87 
88  auto insertionPos = dynamic_cast<MenuBarWindow*>(pWindow) ? mTaskPanes.begin() : mTaskPanes.end();
89  for ( auto p = mTaskPanes.begin(); p != mTaskPanes.end(); ++p )
90  {
91  if ( *p == pWindow )
92  // avoid duplicates
93  return;
94 
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
101  // the result
102  if ( pWindow->IsWindowOrChild( *p ) )
103  {
104  insertionPos = p + 1;
105  break;
106  }
107  if ( (*p)->IsWindowOrChild( pWindow ) )
108  {
109  insertionPos = p;
110  break;
111  }
112  }
113 
114  mTaskPanes.insert( insertionPos, pWindow );
115  pWindow->ImplIsInTaskPaneList( true );
116 }
117 
119 {
120  auto p = ::std::find( mTaskPanes.begin(), mTaskPanes.end(), VclPtr<vcl::Window>(pWindow) );
121  if( p != mTaskPanes.end() )
122  {
123  mTaskPanes.erase( p );
124  pWindow->ImplIsInTaskPaneList( false );
125  }
126 }
127 
129 {
130  auto p = ::std::find( mTaskPanes.begin(), mTaskPanes.end(), VclPtr<vcl::Window>(pWindow) );
131  return p != mTaskPanes.end();
132 }
133 
135 {
136  return rKeyCode.GetCode() == KEY_F6 && !rKeyCode.IsMod2(); // F6
137 }
138 
140 {
141 
142  // F6 cycles through everything and works always
143 
144  // MAV, #i104204#
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
148 
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))
154  {
155  bool bSplitterOnly = aKeyCode.IsMod1() && aKeyCode.IsShift();
156 
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() )
161  {
162  vcl::Window *pWin = p->get();
163 
164  // Ctrl-F6 goes directly to the document
165  if( !pWin->IsDialog() && aKeyCode.IsMod1() && !aKeyCode.IsShift() )
166  {
168  return true;
169  }
170 
171  // activate next task pane
172  vcl::Window *pNextWin = nullptr;
173 
174  if( bSplitterOnly )
175  pNextWin = FindNextSplitter( *p );
176  else
177  pNextWin = FindNextFloat( *p, bForward );
178 
179  if( pNextWin != pWin )
180  {
182  ImplTaskPaneListGrabFocus( pNextWin, bForward );
184  }
185  else
186  {
187  // forward key if no splitter found
188  if( bSplitterOnly )
189  return false;
190 
191  // we did not find another taskpane, so
192  // put focus back into document
194  }
195 
196  return true;
197  }
198 
199  // the focus is not in the list: activate first float if F6 was pressed
200  vcl::Window *pWin;
201  if( bSplitterOnly )
202  pWin = FindNextSplitter( nullptr );
203  else
204  pWin = FindNextFloat( nullptr, bForward );
205  if( pWin )
206  {
207  ImplTaskPaneListGrabFocus( pWin, bForward );
208  return true;
209  }
210  }
211 
212  return false;
213 }
214 
215 // returns next splitter
217 {
218  ::std::stable_sort( mTaskPanes.begin(), mTaskPanes.end(), LTRSort() );
219 
220  auto p = mTaskPanes.begin();
221  if( pWindow )
222  p = std::find(mTaskPanes.begin(), mTaskPanes.end(), pWindow);
223 
224  if( p != mTaskPanes.end() )
225  {
226  unsigned n = mTaskPanes.size();
227  while( --n )
228  {
229  if( pWindow ) // increment before test
230  ++p;
231  if( p == mTaskPanes.end() )
232  p = mTaskPanes.begin();
233  if( (*p)->ImplIsSplitter() && (*p)->IsReallyVisible() && !(*p)->IsDialog() && (*p)->GetParent()->HasChildPathFocus() )
234  {
235  pWindow = (*p).get();
236  break;
237  }
238  if( !pWindow ) // increment after test, otherwise first element is skipped
239  ++p;
240  }
241  }
242 
243  return pWindow;
244 }
245 
246 // returns first valid item (regardless of type) if pWindow==0, otherwise returns next valid float
248 {
249  ::std::stable_sort( mTaskPanes.begin(), mTaskPanes.end(), LTRSort() );
250 
251  if ( !bForward )
252  ::std::reverse( mTaskPanes.begin(), mTaskPanes.end() );
253 
254  auto p = mTaskPanes.begin();
255  if( pWindow )
256  p = std::find(mTaskPanes.begin(), mTaskPanes.end(), pWindow);
257 
258  while( p != mTaskPanes.end() )
259  {
260  if( pWindow ) // increment before test
261  ++p;
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
265  */
266 
267  bool bSkip = false; // used to skip infobar when it has no children
268  if( (*p)->GetType() == WindowType::WINDOW && (*p)->GetChildCount() == 0 )
269  bSkip = true;
270 
271  if( !bSkip && (*p)->IsReallyVisible() && !(*p)->ImplIsSplitter() &&
272  ( (*p)->GetType() != WindowType::MENUBARWINDOW || static_cast<MenuBarWindow*>(p->get())->CanGetFocus() ) )
273  {
274  pWindow = (*p).get();
275  break;
276  }
277  if( !pWindow ) // increment after test, otherwise first element is skipped
278  ++p;
279  }
280 
281  if ( !bForward )
282  ::std::reverse( mTaskPanes.begin(), mTaskPanes.end() );
283 
284  return pWindow;
285 }
286 
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual Point GetPosPixel() const
Definition: window.cxx:2781
bool IsWindowOrChild(const vcl::Window *pWindow, bool bSystemWindow=false) const
Definition: stacking.cxx:1123
SAL_DLLPRIVATE bool ImplIsFloatingWindow() const
Definition: window2.cxx:905
SAL_DLLPRIVATE void ImplIsInTaskPaneList(bool mbIsInTaskList)
Definition: window.cxx:3614
bool mbNoSaveFocus
Definition: svdata.hxx:266
vcl::Window * FindNextFloat(vcl::Window *pWindow, bool bForward)
static bool IsCycleKey(const vcl::KeyCode &rKeyCode)
SAL_DLLPRIVATE void ImplGrabFocus(GetFocusFlags nFlags)
Definition: mouse.cxx:194
sal_Int64 n
sal_uInt16 GetCode() const
Definition: keycod.hxx:49
constexpr sal_uInt16 KEY_F6
Definition: keycodes.hxx:88
size_t pos
SAL_DLLPRIVATE void ImplGrabFocusToDocument(GetFocusFlags nFlags)
Definition: mouse.cxx:398
bool IsDockingWindow() const
Definition: window2.cxx:900
Class that implements the actual window of the menu bar.
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:75
vcl::Window * FindNextSplitter(vcl::Window *pWindow)
bool IsDialog() const
Definition: window2.cxx:996
Point ScreenToOutputPixel(const Point &rPos) const
Definition: window.cxx:2799
Point OutputToAbsoluteScreenPixel(const Point &rPos) const
Definition: window.cxx:2842
vcl::Window * GetWindow(GetWindowType nType) const
Definition: stacking.cxx:1035
const vcl::KeyCode & GetKeyCode() const
Definition: event.hxx:57
bool IsShift() const
Definition: keycod.hxx:54
::std::vector< VclPtr< vcl::Window > > mTaskPanes
bool HandleKeyEvent(const KeyEvent &rKeyEvent)
bool IsMod1() const
Definition: keycod.hxx:56
void * p
void RemoveWindow(vcl::Window *pWindow)
void AddWindow(vcl::Window *pWindow)
bool IsInList(vcl::Window *pWindow)
ImplSVWinData * mpWinData
Definition: svdata.hxx:396
static void ImplTaskPaneListGrabFocus(vcl::Window *pWindow, bool bForward)
bool IsMod2() const
Definition: keycod.hxx:58