1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svtools.hxx" 26 27 #include "svtools/table/defaultinputhandler.hxx" 28 #include "svtools/table/tablecontrolinterface.hxx" 29 30 #include "tabledatawindow.hxx" 31 #include "mousefunction.hxx" 32 33 #include <tools/debug.hxx> 34 #include <vcl/event.hxx> 35 #include <vcl/cursor.hxx> 36 37 //...................................................................................................................... 38 namespace svt { namespace table 39 { 40 //...................................................................................................................... 41 42 typedef ::rtl::Reference< IMouseFunction > PMouseFunction; 43 typedef ::std::vector< PMouseFunction > MouseFunctions; 44 struct DefaultInputHandler_Impl 45 { 46 PMouseFunction pActiveFunction; 47 MouseFunctions aMouseFunctions; 48 }; 49 50 //================================================================================================================== 51 //= DefaultInputHandler 52 //================================================================================================================== 53 //------------------------------------------------------------------------------------------------------------------ DefaultInputHandler()54 DefaultInputHandler::DefaultInputHandler() 55 :m_pImpl( new DefaultInputHandler_Impl ) 56 { 57 m_pImpl->aMouseFunctions.push_back( new ColumnResize ); 58 m_pImpl->aMouseFunctions.push_back( new RowSelection ); 59 m_pImpl->aMouseFunctions.push_back( new ColumnSortHandler ); 60 } 61 62 //------------------------------------------------------------------------------------------------------------------ ~DefaultInputHandler()63 DefaultInputHandler::~DefaultInputHandler() 64 { 65 } 66 67 //------------------------------------------------------------------------------------------------------------------ 68 namespace 69 { lcl_delegateMouseEvent(DefaultInputHandler_Impl & i_impl,ITableControl & i_control,const MouseEvent & i_event,FunctionResult (IMouseFunction::* i_handlerMethod)(ITableControl &,const MouseEvent &))70 bool lcl_delegateMouseEvent( DefaultInputHandler_Impl& i_impl, ITableControl& i_control, const MouseEvent& i_event, 71 FunctionResult ( IMouseFunction::*i_handlerMethod )( ITableControl&, const MouseEvent& ) ) 72 { 73 if ( i_impl.pActiveFunction.is() ) 74 { 75 bool furtherHandler = false; 76 switch ( (i_impl.pActiveFunction.get()->*i_handlerMethod)( i_control, i_event ) ) 77 { 78 case ActivateFunction: 79 OSL_ENSURE( false, "lcl_delegateMouseEvent: unexpected - function already *is* active!" ); 80 break; 81 case ContinueFunction: 82 break; 83 case DeactivateFunction: 84 i_impl.pActiveFunction.clear(); 85 break; 86 case SkipFunction: 87 furtherHandler = true; 88 break; 89 } 90 if ( !furtherHandler ) 91 // handled the event 92 return true; 93 } 94 95 // ask all other handlers 96 bool handled = false; 97 for ( MouseFunctions::iterator handler = i_impl.aMouseFunctions.begin(); 98 ( handler != i_impl.aMouseFunctions.end() ) && !handled; 99 ++handler 100 ) 101 { 102 if ( *handler == i_impl.pActiveFunction ) 103 // we already invoked this function 104 continue; 105 106 switch ( (handler->get()->*i_handlerMethod)( i_control, i_event ) ) 107 { 108 case ActivateFunction: 109 i_impl.pActiveFunction = *handler; 110 handled = true; 111 break; 112 case ContinueFunction: 113 case DeactivateFunction: 114 OSL_ENSURE( false, "lcl_delegateMouseEvent: unexpected: inactivate handler cannot be continued or deactivated!" ); 115 break; 116 case SkipFunction: 117 handled = false; 118 break; 119 } 120 } 121 return handled; 122 } 123 } 124 125 //------------------------------------------------------------------------------------------------------------------ MouseMove(ITableControl & i_tableControl,const MouseEvent & i_event)126 bool DefaultInputHandler::MouseMove( ITableControl& i_tableControl, const MouseEvent& i_event ) 127 { 128 return lcl_delegateMouseEvent( *m_pImpl, i_tableControl, i_event, &IMouseFunction::handleMouseMove ); 129 } 130 131 //------------------------------------------------------------------------------------------------------------------ MouseButtonDown(ITableControl & i_tableControl,const MouseEvent & i_event)132 bool DefaultInputHandler::MouseButtonDown( ITableControl& i_tableControl, const MouseEvent& i_event ) 133 { 134 return lcl_delegateMouseEvent( *m_pImpl, i_tableControl, i_event, &IMouseFunction::handleMouseDown ); 135 } 136 137 //------------------------------------------------------------------------------------------------------------------ MouseButtonUp(ITableControl & i_tableControl,const MouseEvent & i_event)138 bool DefaultInputHandler::MouseButtonUp( ITableControl& i_tableControl, const MouseEvent& i_event ) 139 { 140 return lcl_delegateMouseEvent( *m_pImpl, i_tableControl, i_event, &IMouseFunction::handleMouseUp ); 141 } 142 143 //------------------------------------------------------------------------------------------------------------------ KeyInput(ITableControl & _rControl,const KeyEvent & rKEvt)144 bool DefaultInputHandler::KeyInput( ITableControl& _rControl, const KeyEvent& rKEvt ) 145 { 146 bool bHandled = false; 147 148 const KeyCode& rKeyCode = rKEvt.GetKeyCode(); 149 sal_uInt16 nKeyCode = rKeyCode.GetCode(); 150 151 struct _ActionMapEntry 152 { 153 sal_uInt16 nKeyCode; 154 sal_uInt16 nKeyModifier; 155 TableControlAction eAction; 156 } 157 static aKnownActions[] = { 158 { KEY_DOWN, 0, cursorDown }, 159 { KEY_UP, 0, cursorUp }, 160 { KEY_LEFT, 0, cursorLeft }, 161 { KEY_RIGHT, 0, cursorRight }, 162 { KEY_HOME, 0, cursorToLineStart }, 163 { KEY_END, 0, cursorToLineEnd }, 164 { KEY_PAGEUP, 0, cursorPageUp }, 165 { KEY_PAGEDOWN, 0, cursorPageDown }, 166 { KEY_PAGEUP, KEY_MOD1, cursorToFirstLine }, 167 { KEY_PAGEDOWN, KEY_MOD1, cursorToLastLine }, 168 { KEY_HOME, KEY_MOD1, cursorTopLeft }, 169 { KEY_END, KEY_MOD1, cursorBottomRight }, 170 { KEY_SPACE, KEY_MOD1, cursorSelectRow }, 171 { KEY_UP, KEY_SHIFT, cursorSelectRowUp }, 172 { KEY_DOWN, KEY_SHIFT, cursorSelectRowDown }, 173 { KEY_END, KEY_SHIFT, cursorSelectRowAreaBottom }, 174 { KEY_HOME, KEY_SHIFT, cursorSelectRowAreaTop }, 175 176 { 0, 0, invalidTableControlAction } 177 }; 178 179 const _ActionMapEntry* pActions = aKnownActions; 180 for ( ; pActions->eAction != invalidTableControlAction; ++pActions ) 181 { 182 if ( ( pActions->nKeyCode == nKeyCode ) && ( pActions->nKeyModifier == rKeyCode.GetAllModifier() ) ) 183 { 184 bHandled = _rControl.dispatchAction( pActions->eAction ); 185 break; 186 } 187 } 188 189 return bHandled; 190 } 191 192 //------------------------------------------------------------------------------------------------------------------ GetFocus(ITableControl & _rControl)193 bool DefaultInputHandler::GetFocus( ITableControl& _rControl ) 194 { 195 _rControl.showCursor(); 196 return false; // continue processing 197 } 198 199 //------------------------------------------------------------------------------------------------------------------ LoseFocus(ITableControl & _rControl)200 bool DefaultInputHandler::LoseFocus( ITableControl& _rControl ) 201 { 202 _rControl.hideCursor(); 203 return false; // continue processing 204 } 205 206 //------------------------------------------------------------------------------------------------------------------ RequestHelp(ITableControl & _rControl,const HelpEvent & _rHEvt)207 bool DefaultInputHandler::RequestHelp( ITableControl& _rControl, const HelpEvent& _rHEvt ) 208 { 209 (void)_rControl; 210 (void)_rHEvt; 211 // TODO 212 return false; 213 } 214 215 //------------------------------------------------------------------------------------------------------------------ Command(ITableControl & _rControl,const CommandEvent & _rCEvt)216 bool DefaultInputHandler::Command( ITableControl& _rControl, const CommandEvent& _rCEvt ) 217 { 218 (void)_rControl; 219 (void)_rCEvt; 220 // TODO 221 return false; 222 } 223 224 //------------------------------------------------------------------------------------------------------------------ PreNotify(ITableControl & _rControl,NotifyEvent & _rNEvt)225 bool DefaultInputHandler::PreNotify( ITableControl& _rControl, NotifyEvent& _rNEvt ) 226 { 227 (void)_rControl; 228 (void)_rNEvt; 229 // TODO 230 return false; 231 } 232 233 //------------------------------------------------------------------------------------------------------------------ Notify(ITableControl & _rControl,NotifyEvent & _rNEvt)234 bool DefaultInputHandler::Notify( ITableControl& _rControl, NotifyEvent& _rNEvt ) 235 { 236 (void)_rControl; 237 (void)_rNEvt; 238 // TODO 239 return false; 240 } 241 //...................................................................................................................... 242 } } // namespace svt::table 243 //...................................................................................................................... 244