/************************************************************************* * * $RCSfile: taskpanelist.cxx,v $ * * $Revision: 1.7 $ * * last change: $Author: ssa $ $Date: 2002-03-15 13:51:47 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses * * - GNU Lesser General Public License Version 2.1 * - Sun Industry Standards Source License Version 1.1 * * Sun Microsystems Inc., October, 2000 * * GNU Lesser General Public License Version 2.1 * ============================================= * Copyright 2000 by Sun Microsystems, Inc. * 901 San Antonio Road, Palo Alto, CA 94303, USA * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * * Sun Industry Standards Source License Version 1.1 * ================================================= * The contents of this file are subject to the Sun Industry Standards * Source License Version 1.1 (the "License"); You may not use this file * except in compliance with the License. You may obtain a copy of the * License at http://www.openoffice.org/license.html. * * Software provided under this License is provided on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. * See the License for the specific provisions governing your rights and * obligations concerning the Software. * * The Initial Developer of the Original Code is: Sun Microsystems, Inc. * * Copyright: 2000 by Sun Microsystems, Inc. * * All Rights Reserved. * * Contributor(s): _______________________________________ * * ************************************************************************/ #ifndef _SV_SVDATA_HXX #include #endif #ifndef _RCID_H #include #endif #ifndef _SV_DOCKWIN_HXX #include #endif #include #include #include static Point ImplGetPos( const Window *w ) { Point pos; if( w->ImplIsDockingWindow() ) { pos = ((DockingWindow*)w)->GetPosPixel(); Window *pF = ((DockingWindow*)w)->GetFloatingWindow(); if( pF ) pos = pF->OutputToAbsoluteScreenPixel( pF->ScreenToOutputPixel( pos ) ); else pos = w->OutputToAbsoluteScreenPixel( pos ); } else pos = w->OutputToAbsoluteScreenPixel( w->GetPosPixel() ); return pos; } // compares window pos left-to-right struct LTRSort : public ::std::binary_function< const Window*, const Window*, bool > { bool operator()( const Window* w1, const Window* w2 ) const { Point pos1(ImplGetPos( w1 )); Point pos2(ImplGetPos( w2 )); if( pos1.X() == pos2.X() ) return ( pos1.Y() < pos2.Y() ); else return ( pos1.X() < pos2.X() ); } }; struct LTRSortBackward : public ::std::binary_function< const Window*, const Window*, bool > { bool operator()( const Window* w2, const Window* w1 ) const { Point pos1(ImplGetPos( w1 )); Point pos2(ImplGetPos( w2 )); if( pos1.X() == pos2.X() ) return ( pos1.Y() < pos2.Y() ); else return ( pos1.X() < pos2.X() ); } }; // -------------------------------------------------- TaskPaneList::TaskPaneList() { } TaskPaneList::~TaskPaneList() { } // -------------------------------------------------- void TaskPaneList::AddWindow( Window *pWindow ) { bool bDockingWindow=false; bool bToolbox=false; bool bDialog=false; bool bUnknown=false; if( pWindow ) { if( pWindow->GetType() == RSC_DOCKINGWINDOW ) bDockingWindow = true; else if( pWindow->GetType() == RSC_TOOLBOX ) bToolbox = true; else if( pWindow->IsDialog() ) bDialog = true; else bUnknown = true; ::std::vector< Window* >::iterator p; p = ::std::find( mTaskPanes.begin(), mTaskPanes.end(), pWindow ); // avoid duplicates if( p == mTaskPanes.end() ) // not found mTaskPanes.push_back( pWindow ); } } // -------------------------------------------------- void TaskPaneList::RemoveWindow( Window *pWindow ) { ::std::vector< Window* >::iterator p; p = ::std::find( mTaskPanes.begin(), mTaskPanes.end(), pWindow ); if( p != mTaskPanes.end() ) mTaskPanes.erase( p ); } // -------------------------------------------------- BOOL TaskPaneList::HandleKeyEvent( KeyEvent aKeyEvent ) { BOOL bFloatsOnly = FALSE; BOOL bFocusInList = FALSE; KeyCode aKeyCode = aKeyEvent.GetKeyCode(); BOOL bForward = !aKeyCode.IsShift(); if( ( aKeyCode.IsMod1() && aKeyCode.GetCode() == KEY_TAB ) // Ctrl-TAB || ( bFloatsOnly = ( aKeyCode.GetCode()) == KEY_F6 ) // F6 ) { // is the focus in the list ? BOOL bHasFocus = FALSE; ::std::vector< Window* >::iterator p = mTaskPanes.begin(); while( p != mTaskPanes.end() ) { Window *pWin = *p; if( (*p)->HasChildPathFocus( TRUE ) ) { // F6 works only in floaters if( bFloatsOnly && (*p)->GetType() != RSC_DOCKINGWINDOW && !(*p)->IsDialog() ) return FALSE; bFocusInList = TRUE; // activate next task pane Window *pNextWin = bFloatsOnly ? FindNextFloat( *p, bForward ) : FindNextPane( *p, bForward ); if( pNextWin != pWin ) { ImplGetSVData()->maWinData.mbNoSaveFocus = TRUE; pNextWin->GrabFocus(); ImplGetSVData()->maWinData.mbNoSaveFocus = FALSE; } else { // we did not find another taskpane, so // put focus back into document: use frame win of topmost parent while( pWin ) { if( !pWin->GetParent() ) { pWin->ImplGetFrameWindow()->GetWindow( WINDOW_CLIENT )->GrabFocus(); break; } pWin = pWin->GetParent(); } } return TRUE; } else p++; } // the focus is not in the list: activate first float if F6 was pressed if( !bFocusInList && bFloatsOnly ) { Window *pWin = FindNextFloat( NULL, bForward ); if( pWin ) { pWin->GrabFocus(); return TRUE; } } } return FALSE; } // -------------------------------------------------- // returns next valid pane Window* TaskPaneList::FindNextPane( Window *pWindow, BOOL bForward ) { if( bForward ) ::std::stable_sort( mTaskPanes.begin(), mTaskPanes.end(), LTRSort() ); else ::std::stable_sort( mTaskPanes.begin(), mTaskPanes.end(), LTRSortBackward() ); ::std::vector< Window* >::iterator p = mTaskPanes.begin(); while( p != mTaskPanes.end() ) { if( *p == pWindow ) { unsigned n = mTaskPanes.size(); while( --n ) { if( ++p == mTaskPanes.end() ) p = mTaskPanes.begin(); if( (*p)->IsVisible() ) return *p; } break; } else ++p; } return pWindow; // nothing found } // -------------------------------------------------- // returns first valid float if pWindow==0, otherwise returns next valid float Window* TaskPaneList::FindNextFloat( Window *pWindow, BOOL bForward ) { if( bForward ) ::std::stable_sort( mTaskPanes.begin(), mTaskPanes.end(), LTRSort() ); else ::std::stable_sort( mTaskPanes.begin(), mTaskPanes.end(), LTRSortBackward() ); ::std::vector< Window* >::iterator p = mTaskPanes.begin(); while( p != mTaskPanes.end() ) { if( !pWindow || *p == pWindow ) { while( p != mTaskPanes.end() ) { if( pWindow ) // increment before test ++p; if( p == mTaskPanes.end() ) return pWindow; // do not wrap, send focus back to document at end of list if( (*p)->IsVisible() && ( (*p)->GetType() == RSC_DOCKINGWINDOW || (*p)->IsDialog() ) ) return *p; if( !pWindow ) // increment after test, otherwise first element is skipped ++p; } break; } else ++p; } return pWindow; // nothing found } // --------------------------------------------------