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