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/taskpanelist.hxx>
22 
23 #include <svdata.hxx>
24 #include "menubarwindow.hxx"
25 
26 #include <algorithm>
27 
28 namespace {
29 
30 Point ImplTaskPaneListGetPos( const vcl::Window *w )
31 {
32  Point pos;
33  if( w->IsDockingWindow() )
34  {
35  pos = static_cast<const DockingWindow*>(w)->GetPosPixel();
36  vcl::Window *pF = static_cast<const DockingWindow*>(w)->GetFloatingWindow();
37  if( pF )
38  pos = pF->OutputToAbsoluteScreenPixel( pF->ScreenToOutputPixel( pos ) );
39  else
40  pos = w->OutputToAbsoluteScreenPixel( pos );
41  }
42  else
44 
45  return pos;
46 }
47 
48 // compares window pos left-to-right
49 struct LTRSort
50 {
51  bool operator()( const vcl::Window* w1, const vcl::Window* w2 ) const
52  {
53  Point pos1(ImplTaskPaneListGetPos( w1 ));
54  Point pos2(ImplTaskPaneListGetPos( w2 ));
55 
56  if( pos1.X() == pos2.X() )
57  return ( pos1.Y() < pos2.Y() );
58  else
59  return ( pos1.X() < pos2.X() );
60  }
61 };
62 
63 }
64 
65 static void ImplTaskPaneListGrabFocus( vcl::Window *pWindow, bool bForward )
66 {
67  // put focus in child of floating windows which is typically a toolbar
68  // that can deal with the focus
69  if( pWindow->ImplIsFloatingWindow() && pWindow->GetWindow( GetWindowType::FirstChild ) )
70  pWindow = pWindow->GetWindow( GetWindowType::FirstChild );
72 }
73 
75 {
76 }
77 
79 {
80 }
81 
83 {
84  if( pWindow )
85  {
86  auto insertionPos = dynamic_cast<MenuBarWindow*>(pWindow) ? mTaskPanes.begin() : mTaskPanes.end();
87  for ( auto p = mTaskPanes.begin(); p != mTaskPanes.end(); ++p )
88  {
89  if ( *p == pWindow )
90  // avoid duplicates
91  return;
92 
93  // If the new window is the child of an existing pane window, or vice versa,
94  // ensure that in our pane list, *first* the child window appears, *then*
95  // the ancestor window.
96  // This is necessary for HandleKeyEvent: There, the list is traveled from the
97  // beginning, until the first window is found which has the ChildPathFocus. Now
98  // if this would be the ancestor window of another pane window, this would fudge
99  // the result
100  if ( pWindow->IsWindowOrChild( *p ) )
101  {
102  insertionPos = p + 1;
103  break;
104  }
105  if ( (*p)->IsWindowOrChild( pWindow ) )
106  {
107  insertionPos = p;
108  break;
109  }
110  }
111 
112  mTaskPanes.insert( insertionPos, pWindow );
113  pWindow->ImplIsInTaskPaneList( true );
114  }
115 }
116 
118 {
119  auto p = ::std::find( mTaskPanes.begin(), mTaskPanes.end(), VclPtr<vcl::Window>(pWindow) );
120  if( p != mTaskPanes.end() )
121  {
122  mTaskPanes.erase( p );
123  pWindow->ImplIsInTaskPaneList( false );
124  }
125 }
126 
128 {
129  auto p = ::std::find( mTaskPanes.begin(), mTaskPanes.end(), VclPtr<vcl::Window>(pWindow) );
130  return p != mTaskPanes.end();
131 }
132 
134 {
135  return rKeyCode.GetCode() == KEY_F6 && !rKeyCode.IsMod2(); // F6
136 }
137 
139 {
140 
141  // F6 cycles through everything and works always
142 
143  // MAV, #i104204#
144  // The old design was the following one:
145  // < Ctrl-TAB cycles through Menubar, Toolbars and Floatingwindows only and is
146  // < only active if one of those items has the focus
147 
148  // Since the design of Ctrl-Tab looks to be inconsistent ( non-modal dialogs are not reachable
149  // and the shortcut conflicts with tab-control shortcut ), it is no more supported
150  vcl::KeyCode aKeyCode = rKeyEvent.GetKeyCode();
151  bool bForward = !aKeyCode.IsShift();
152  if (TaskPaneList::IsCycleKey(aKeyCode))
153  {
154  bool bSplitterOnly = aKeyCode.IsMod1() && aKeyCode.IsShift();
155 
156  // is the focus in the list ?
157  auto p = std::find_if(mTaskPanes.begin(), mTaskPanes.end(),
158  [](const VclPtr<vcl::Window>& rWinPtr) { return rWinPtr->HasChildPathFocus( true ); });
159  if( p != mTaskPanes.end() )
160  {
161  vcl::Window *pWin = p->get();
162 
163  // Ctrl-F6 goes directly to the document
164  if( !pWin->IsDialog() && aKeyCode.IsMod1() && !aKeyCode.IsShift() )
165  {
167  return true;
168  }
169 
170  // activate next task pane
171  vcl::Window *pNextWin = nullptr;
172 
173  if( bSplitterOnly )
174  pNextWin = FindNextSplitter( *p );
175  else
176  pNextWin = FindNextFloat( *p, bForward );
177 
178  if( pNextWin != pWin )
179  {
181  ImplTaskPaneListGrabFocus( pNextWin, bForward );
183  }
184  else
185  {
186  // forward key if no splitter found
187  if( bSplitterOnly )
188  return false;
189 
190  // we did not find another taskpane, so
191  // put focus back into document
193  }
194 
195  return true;
196  }
197 
198  // the focus is not in the list: activate first float if F6 was pressed
199  vcl::Window *pWin;
200  if( bSplitterOnly )
201  pWin = FindNextSplitter( nullptr );
202  else
203  pWin = FindNextFloat( nullptr, bForward );
204  if( pWin )
205  {
206  ImplTaskPaneListGrabFocus( pWin, bForward );
207  return true;
208  }
209  }
210 
211  return false;
212 }
213 
214 // returns next splitter
216 {
217  ::std::stable_sort( mTaskPanes.begin(), mTaskPanes.end(), LTRSort() );
218 
219  auto p = mTaskPanes.begin();
220  if( pWindow )
221  p = std::find(mTaskPanes.begin(), mTaskPanes.end(), pWindow);
222 
223  if( p != mTaskPanes.end() )
224  {
225  unsigned n = mTaskPanes.size();
226  while( --n )
227  {
228  if( pWindow ) // increment before test
229  ++p;
230  if( p == mTaskPanes.end() )
231  p = mTaskPanes.begin();
232  if( (*p)->ImplIsSplitter() && (*p)->IsReallyVisible() && !(*p)->IsDialog() && (*p)->GetParent()->HasChildPathFocus() )
233  {
234  pWindow = (*p).get();
235  break;
236  }
237  if( !pWindow ) // increment after test, otherwise first element is skipped
238  ++p;
239  }
240  }
241 
242  return pWindow;
243 }
244 
245 // returns first valid item (regardless of type) if pWindow==0, otherwise returns next valid float
247 {
248  ::std::stable_sort( mTaskPanes.begin(), mTaskPanes.end(), LTRSort() );
249 
250  if ( !bForward )
251  ::std::reverse( mTaskPanes.begin(), mTaskPanes.end() );
252 
253  auto p = mTaskPanes.begin();
254  if( pWindow )
255  p = std::find(mTaskPanes.begin(), mTaskPanes.end(), pWindow);
256 
257  while( p != mTaskPanes.end() )
258  {
259  if( pWindow ) // increment before test
260  ++p;
261  if( p == mTaskPanes.end() )
262  break; // do not wrap, send focus back to document at end of list
263  /* #i83908# do not use the menubar if it is native and invisible
264  */
265 
266  bool bSkip = false; // used to skip infobar when it has no children
267  if( (*p)->GetType() == WindowType::WINDOW && (*p)->GetChildCount() == 0 )
268  bSkip = true;
269 
270  if( !bSkip && (*p)->IsReallyVisible() && !(*p)->ImplIsSplitter() &&
271  ( (*p)->GetType() != WindowType::MENUBARWINDOW || static_cast<MenuBarWindow*>(p->get())->CanGetFocus() ) )
272  {
273  pWindow = (*p).get();
274  break;
275  }
276  if( !pWindow ) // increment after test, otherwise first element is skipped
277  ++p;
278  }
279 
280  if ( !bForward )
281  ::std::reverse( mTaskPanes.begin(), mTaskPanes.end() );
282 
283  return pWindow;
284 }
285 
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual Point GetPosPixel() const
Definition: window.cxx:2838
bool IsWindowOrChild(const vcl::Window *pWindow, bool bSystemWindow=false) const
Definition: stacking.cxx:1134
SAL_DLLPRIVATE bool ImplIsFloatingWindow() const
Definition: window2.cxx:911
SAL_DLLPRIVATE void ImplIsInTaskPaneList(bool mbIsInTaskList)
Definition: window.cxx:3646
bool mbNoSaveFocus
Definition: svdata.hxx:263
vcl::Window * FindNextFloat(vcl::Window *pWindow, bool bForward)
static bool IsCycleKey(const vcl::KeyCode &rKeyCode)
SAL_DLLPRIVATE void ImplGrabFocus(GetFocusFlags nFlags)
Definition: mouse.cxx:195
sal_Int64 n
sal_uInt16 GetCode() const
Definition: keycod.hxx:53
constexpr sal_uInt16 KEY_F6
Definition: keycodes.hxx:88
size_t pos
SAL_DLLPRIVATE void ImplGrabFocusToDocument(GetFocusFlags nFlags)
Definition: mouse.cxx:393
bool IsDockingWindow() const
Definition: window2.cxx:906
Class that implements the actual window of the menu bar.
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:76
vcl::Window * FindNextSplitter(vcl::Window *pWindow)
bool IsDialog() const
Definition: window2.cxx:1002
Point ScreenToOutputPixel(const Point &rPos) const
Definition: window.cxx:2856
Point OutputToAbsoluteScreenPixel(const Point &rPos) const
Definition: window.cxx:2899
vcl::Window * GetWindow(GetWindowType nType) const
Definition: stacking.cxx:1046
const vcl::KeyCode & GetKeyCode() const
Definition: event.hxx:54
bool IsShift() const
Definition: keycod.hxx:58
::std::vector< VclPtr< vcl::Window > > mTaskPanes
bool HandleKeyEvent(const KeyEvent &rKeyEvent)
bool IsMod1() const
Definition: keycod.hxx:60
void * p
void RemoveWindow(vcl::Window *pWindow)
void AddWindow(vcl::Window *pWindow)
bool IsInList(vcl::Window *pWindow)
ImplSVWinData * mpWinData
Definition: svdata.hxx:395
static void ImplTaskPaneListGrabFocus(vcl::Window *pWindow, bool bForward)
bool IsMod2() const
Definition: keycod.hxx:62