Bump version to 5.0-14
[LibreOffice.git] / svtools / source / table / defaultinputhandler.cxx
blob6f36879c38f6383780c69e60489de48e95c06f7a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "table/defaultinputhandler.hxx"
22 #include "table/tablecontrolinterface.hxx"
24 #include "tabledatawindow.hxx"
25 #include "mousefunction.hxx"
27 #include <vcl/event.hxx>
28 #include <vcl/cursor.hxx>
31 namespace svt { namespace table
35 typedef ::rtl::Reference< MouseFunction > PMouseFunction;
36 typedef ::std::vector< PMouseFunction > MouseFunctions;
37 struct DefaultInputHandler_Impl
39 PMouseFunction pActiveFunction;
40 MouseFunctions aMouseFunctions;
44 //= DefaultInputHandler
47 DefaultInputHandler::DefaultInputHandler()
48 :m_pImpl( new DefaultInputHandler_Impl )
50 m_pImpl->aMouseFunctions.push_back( new ColumnResize );
51 m_pImpl->aMouseFunctions.push_back( new RowSelection );
52 m_pImpl->aMouseFunctions.push_back( new ColumnSortHandler );
56 DefaultInputHandler::~DefaultInputHandler()
61 namespace
63 bool lcl_delegateMouseEvent( DefaultInputHandler_Impl& i_impl, ITableControl& i_control, const MouseEvent& i_event,
64 FunctionResult ( MouseFunction::*i_handlerMethod )( ITableControl&, const MouseEvent& ) )
66 if ( i_impl.pActiveFunction.is() )
68 bool furtherHandler = false;
69 switch ( (i_impl.pActiveFunction.get()->*i_handlerMethod)( i_control, i_event ) )
71 case ActivateFunction:
72 OSL_ENSURE( false, "lcl_delegateMouseEvent: unexpected - function already *is* active!" );
73 break;
74 case ContinueFunction:
75 break;
76 case DeactivateFunction:
77 i_impl.pActiveFunction.clear();
78 break;
79 case SkipFunction:
80 furtherHandler = true;
81 break;
83 if ( !furtherHandler )
84 // handled the event
85 return true;
88 // ask all other handlers
89 bool handled = false;
90 for ( MouseFunctions::iterator handler = i_impl.aMouseFunctions.begin();
91 ( handler != i_impl.aMouseFunctions.end() ) && !handled;
92 ++handler
95 if ( *handler == i_impl.pActiveFunction )
96 // we already invoked this function
97 continue;
99 switch ( (handler->get()->*i_handlerMethod)( i_control, i_event ) )
101 case ActivateFunction:
102 i_impl.pActiveFunction = *handler;
103 handled = true;
104 break;
105 case ContinueFunction:
106 case DeactivateFunction:
107 OSL_ENSURE( false, "lcl_delegateMouseEvent: unexpected: inactivate handler cannot be continued or deactivated!" );
108 break;
109 case SkipFunction:
110 handled = false;
111 break;
114 return handled;
119 bool DefaultInputHandler::MouseMove( ITableControl& i_tableControl, const MouseEvent& i_event )
121 return lcl_delegateMouseEvent( *m_pImpl, i_tableControl, i_event, &MouseFunction::handleMouseMove );
125 bool DefaultInputHandler::MouseButtonDown( ITableControl& i_tableControl, const MouseEvent& i_event )
127 return lcl_delegateMouseEvent( *m_pImpl, i_tableControl, i_event, &MouseFunction::handleMouseDown );
131 bool DefaultInputHandler::MouseButtonUp( ITableControl& i_tableControl, const MouseEvent& i_event )
133 return lcl_delegateMouseEvent( *m_pImpl, i_tableControl, i_event, &MouseFunction::handleMouseUp );
137 bool DefaultInputHandler::KeyInput( ITableControl& _rControl, const KeyEvent& rKEvt )
139 bool bHandled = false;
141 const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode();
142 sal_uInt16 nKeyCode = rKeyCode.GetCode();
144 struct _ActionMapEntry
146 sal_uInt16 nKeyCode;
147 sal_uInt16 nKeyModifier;
148 TableControlAction eAction;
150 static const aKnownActions[] = {
151 { KEY_DOWN, 0, cursorDown },
152 { KEY_UP, 0, cursorUp },
153 { KEY_LEFT, 0, cursorLeft },
154 { KEY_RIGHT, 0, cursorRight },
155 { KEY_HOME, 0, cursorToLineStart },
156 { KEY_END, 0, cursorToLineEnd },
157 { KEY_PAGEUP, 0, cursorPageUp },
158 { KEY_PAGEDOWN, 0, cursorPageDown },
159 { KEY_PAGEUP, KEY_MOD1, cursorToFirstLine },
160 { KEY_PAGEDOWN, KEY_MOD1, cursorToLastLine },
161 { KEY_HOME, KEY_MOD1, cursorTopLeft },
162 { KEY_END, KEY_MOD1, cursorBottomRight },
163 { KEY_SPACE, KEY_MOD1, cursorSelectRow },
164 { KEY_UP, KEY_SHIFT, cursorSelectRowUp },
165 { KEY_DOWN, KEY_SHIFT, cursorSelectRowDown },
166 { KEY_END, KEY_SHIFT, cursorSelectRowAreaBottom },
167 { KEY_HOME, KEY_SHIFT, cursorSelectRowAreaTop },
169 { 0, 0, invalidTableControlAction }
172 const _ActionMapEntry* pActions = aKnownActions;
173 for ( ; pActions->eAction != invalidTableControlAction; ++pActions )
175 if ( ( pActions->nKeyCode == nKeyCode ) && ( pActions->nKeyModifier == rKeyCode.GetModifier() ) )
177 bHandled = _rControl.dispatchAction( pActions->eAction );
178 break;
182 return bHandled;
186 bool DefaultInputHandler::GetFocus( ITableControl& _rControl )
188 _rControl.showCursor();
189 return false; // continue processing
193 bool DefaultInputHandler::LoseFocus( ITableControl& _rControl )
195 _rControl.hideCursor();
196 return false; // continue processing
200 bool DefaultInputHandler::RequestHelp( ITableControl& _rControl, const HelpEvent& _rHEvt )
202 (void)_rControl;
203 (void)_rHEvt;
204 // TODO
205 return false;
209 bool DefaultInputHandler::Command( ITableControl& _rControl, const CommandEvent& _rCEvt )
211 (void)_rControl;
212 (void)_rCEvt;
213 // TODO
214 return false;
218 bool DefaultInputHandler::PreNotify( ITableControl& _rControl, NotifyEvent& _rNEvt )
220 (void)_rControl;
221 (void)_rNEvt;
222 // TODO
223 return false;
227 bool DefaultInputHandler::Notify( ITableControl& _rControl, NotifyEvent& _rNEvt )
229 (void)_rControl;
230 (void)_rNEvt;
231 // TODO
232 return false;
235 } } // namespace svt::table
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */