1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3*cdf0e10cSrcweir * 4*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 7*cdf0e10cSrcweir * 8*cdf0e10cSrcweir * This file is part of OpenOffice.org. 9*cdf0e10cSrcweir * 10*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 11*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 12*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 13*cdf0e10cSrcweir * 14*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 15*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 16*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 18*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 19*cdf0e10cSrcweir * 20*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 21*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 22*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 23*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 24*cdf0e10cSrcweir * 25*cdf0e10cSrcweir ************************************************************************/ 26*cdf0e10cSrcweir 27*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 28*cdf0e10cSrcweir #include "precompiled_svtools.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "svtools/table/defaultinputhandler.hxx" 31*cdf0e10cSrcweir #include "svtools/table/tablecontrolinterface.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "tabledatawindow.hxx" 34*cdf0e10cSrcweir #include "mousefunction.hxx" 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <tools/debug.hxx> 37*cdf0e10cSrcweir #include <vcl/event.hxx> 38*cdf0e10cSrcweir #include <vcl/cursor.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir //...................................................................................................................... 41*cdf0e10cSrcweir namespace svt { namespace table 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir //...................................................................................................................... 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir typedef ::rtl::Reference< IMouseFunction > PMouseFunction; 46*cdf0e10cSrcweir typedef ::std::vector< PMouseFunction > MouseFunctions; 47*cdf0e10cSrcweir struct DefaultInputHandler_Impl 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir PMouseFunction pActiveFunction; 50*cdf0e10cSrcweir MouseFunctions aMouseFunctions; 51*cdf0e10cSrcweir }; 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir //================================================================================================================== 54*cdf0e10cSrcweir //= DefaultInputHandler 55*cdf0e10cSrcweir //================================================================================================================== 56*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 57*cdf0e10cSrcweir DefaultInputHandler::DefaultInputHandler() 58*cdf0e10cSrcweir :m_pImpl( new DefaultInputHandler_Impl ) 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir m_pImpl->aMouseFunctions.push_back( new ColumnResize ); 61*cdf0e10cSrcweir m_pImpl->aMouseFunctions.push_back( new RowSelection ); 62*cdf0e10cSrcweir m_pImpl->aMouseFunctions.push_back( new ColumnSortHandler ); 63*cdf0e10cSrcweir } 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 66*cdf0e10cSrcweir DefaultInputHandler::~DefaultInputHandler() 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 71*cdf0e10cSrcweir namespace 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir bool lcl_delegateMouseEvent( DefaultInputHandler_Impl& i_impl, ITableControl& i_control, const MouseEvent& i_event, 74*cdf0e10cSrcweir FunctionResult ( IMouseFunction::*i_handlerMethod )( ITableControl&, const MouseEvent& ) ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir if ( i_impl.pActiveFunction.is() ) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir bool furtherHandler = false; 79*cdf0e10cSrcweir switch ( (i_impl.pActiveFunction.get()->*i_handlerMethod)( i_control, i_event ) ) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir case ActivateFunction: 82*cdf0e10cSrcweir OSL_ENSURE( false, "lcl_delegateMouseEvent: unexpected - function already *is* active!" ); 83*cdf0e10cSrcweir break; 84*cdf0e10cSrcweir case ContinueFunction: 85*cdf0e10cSrcweir break; 86*cdf0e10cSrcweir case DeactivateFunction: 87*cdf0e10cSrcweir i_impl.pActiveFunction.clear(); 88*cdf0e10cSrcweir break; 89*cdf0e10cSrcweir case SkipFunction: 90*cdf0e10cSrcweir furtherHandler = true; 91*cdf0e10cSrcweir break; 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir if ( !furtherHandler ) 94*cdf0e10cSrcweir // handled the event 95*cdf0e10cSrcweir return true; 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir // ask all other handlers 99*cdf0e10cSrcweir bool handled = false; 100*cdf0e10cSrcweir for ( MouseFunctions::iterator handler = i_impl.aMouseFunctions.begin(); 101*cdf0e10cSrcweir ( handler != i_impl.aMouseFunctions.end() ) && !handled; 102*cdf0e10cSrcweir ++handler 103*cdf0e10cSrcweir ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir if ( *handler == i_impl.pActiveFunction ) 106*cdf0e10cSrcweir // we already invoked this function 107*cdf0e10cSrcweir continue; 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir switch ( (handler->get()->*i_handlerMethod)( i_control, i_event ) ) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir case ActivateFunction: 112*cdf0e10cSrcweir i_impl.pActiveFunction = *handler; 113*cdf0e10cSrcweir handled = true; 114*cdf0e10cSrcweir break; 115*cdf0e10cSrcweir case ContinueFunction: 116*cdf0e10cSrcweir case DeactivateFunction: 117*cdf0e10cSrcweir OSL_ENSURE( false, "lcl_delegateMouseEvent: unexpected: inactivate handler cannot be continued or deactivated!" ); 118*cdf0e10cSrcweir break; 119*cdf0e10cSrcweir case SkipFunction: 120*cdf0e10cSrcweir handled = false; 121*cdf0e10cSrcweir break; 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir return handled; 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 129*cdf0e10cSrcweir bool DefaultInputHandler::MouseMove( ITableControl& i_tableControl, const MouseEvent& i_event ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir return lcl_delegateMouseEvent( *m_pImpl, i_tableControl, i_event, &IMouseFunction::handleMouseMove ); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 135*cdf0e10cSrcweir bool DefaultInputHandler::MouseButtonDown( ITableControl& i_tableControl, const MouseEvent& i_event ) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir return lcl_delegateMouseEvent( *m_pImpl, i_tableControl, i_event, &IMouseFunction::handleMouseDown ); 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 141*cdf0e10cSrcweir bool DefaultInputHandler::MouseButtonUp( ITableControl& i_tableControl, const MouseEvent& i_event ) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir return lcl_delegateMouseEvent( *m_pImpl, i_tableControl, i_event, &IMouseFunction::handleMouseUp ); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 147*cdf0e10cSrcweir bool DefaultInputHandler::KeyInput( ITableControl& _rControl, const KeyEvent& rKEvt ) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir bool bHandled = false; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir const KeyCode& rKeyCode = rKEvt.GetKeyCode(); 152*cdf0e10cSrcweir sal_uInt16 nKeyCode = rKeyCode.GetCode(); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir struct _ActionMapEntry 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir sal_uInt16 nKeyCode; 157*cdf0e10cSrcweir sal_uInt16 nKeyModifier; 158*cdf0e10cSrcweir TableControlAction eAction; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir static aKnownActions[] = { 161*cdf0e10cSrcweir { KEY_DOWN, 0, cursorDown }, 162*cdf0e10cSrcweir { KEY_UP, 0, cursorUp }, 163*cdf0e10cSrcweir { KEY_LEFT, 0, cursorLeft }, 164*cdf0e10cSrcweir { KEY_RIGHT, 0, cursorRight }, 165*cdf0e10cSrcweir { KEY_HOME, 0, cursorToLineStart }, 166*cdf0e10cSrcweir { KEY_END, 0, cursorToLineEnd }, 167*cdf0e10cSrcweir { KEY_PAGEUP, 0, cursorPageUp }, 168*cdf0e10cSrcweir { KEY_PAGEDOWN, 0, cursorPageDown }, 169*cdf0e10cSrcweir { KEY_PAGEUP, KEY_MOD1, cursorToFirstLine }, 170*cdf0e10cSrcweir { KEY_PAGEDOWN, KEY_MOD1, cursorToLastLine }, 171*cdf0e10cSrcweir { KEY_HOME, KEY_MOD1, cursorTopLeft }, 172*cdf0e10cSrcweir { KEY_END, KEY_MOD1, cursorBottomRight }, 173*cdf0e10cSrcweir { KEY_SPACE, KEY_MOD1, cursorSelectRow }, 174*cdf0e10cSrcweir { KEY_UP, KEY_SHIFT, cursorSelectRowUp }, 175*cdf0e10cSrcweir { KEY_DOWN, KEY_SHIFT, cursorSelectRowDown }, 176*cdf0e10cSrcweir { KEY_END, KEY_SHIFT, cursorSelectRowAreaBottom }, 177*cdf0e10cSrcweir { KEY_HOME, KEY_SHIFT, cursorSelectRowAreaTop }, 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir { 0, 0, invalidTableControlAction } 180*cdf0e10cSrcweir }; 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir const _ActionMapEntry* pActions = aKnownActions; 183*cdf0e10cSrcweir for ( ; pActions->eAction != invalidTableControlAction; ++pActions ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir if ( ( pActions->nKeyCode == nKeyCode ) && ( pActions->nKeyModifier == rKeyCode.GetAllModifier() ) ) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir bHandled = _rControl.dispatchAction( pActions->eAction ); 188*cdf0e10cSrcweir break; 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir return bHandled; 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 196*cdf0e10cSrcweir bool DefaultInputHandler::GetFocus( ITableControl& _rControl ) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir _rControl.showCursor(); 199*cdf0e10cSrcweir return false; // continue processing 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 203*cdf0e10cSrcweir bool DefaultInputHandler::LoseFocus( ITableControl& _rControl ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir _rControl.hideCursor(); 206*cdf0e10cSrcweir return false; // continue processing 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 210*cdf0e10cSrcweir bool DefaultInputHandler::RequestHelp( ITableControl& _rControl, const HelpEvent& _rHEvt ) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir (void)_rControl; 213*cdf0e10cSrcweir (void)_rHEvt; 214*cdf0e10cSrcweir // TODO 215*cdf0e10cSrcweir return false; 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 219*cdf0e10cSrcweir bool DefaultInputHandler::Command( ITableControl& _rControl, const CommandEvent& _rCEvt ) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir (void)_rControl; 222*cdf0e10cSrcweir (void)_rCEvt; 223*cdf0e10cSrcweir // TODO 224*cdf0e10cSrcweir return false; 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 228*cdf0e10cSrcweir bool DefaultInputHandler::PreNotify( ITableControl& _rControl, NotifyEvent& _rNEvt ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir (void)_rControl; 231*cdf0e10cSrcweir (void)_rNEvt; 232*cdf0e10cSrcweir // TODO 233*cdf0e10cSrcweir return false; 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 237*cdf0e10cSrcweir bool DefaultInputHandler::Notify( ITableControl& _rControl, NotifyEvent& _rNEvt ) 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir (void)_rControl; 240*cdf0e10cSrcweir (void)_rNEvt; 241*cdf0e10cSrcweir // TODO 242*cdf0e10cSrcweir return false; 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir //...................................................................................................................... 245*cdf0e10cSrcweir } } // namespace svt::table 246*cdf0e10cSrcweir //...................................................................................................................... 247