1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <controls/table/defaultinputhandler.hxx>
21 #include <controls/table/tablecontrolinterface.hxx>
23 #include <vcl/event.hxx>
24 #include <osl/diagnose.h>
30 //= DefaultInputHandler
33 DefaultInputHandler::DefaultInputHandler()
35 aMouseFunctions
.push_back( new ColumnResize
);
36 aMouseFunctions
.push_back( new RowSelection
);
37 aMouseFunctions
.push_back( new ColumnSortHandler
);
41 DefaultInputHandler::~DefaultInputHandler()
46 bool DefaultInputHandler::delegateMouseEvent( ITableControl
& i_control
, const MouseEvent
& i_event
,
47 FunctionResult ( MouseFunction::*i_handlerMethod
)( ITableControl
&, const MouseEvent
& ) )
49 if ( pActiveFunction
.is() )
51 bool furtherHandler
= false;
52 switch ( (pActiveFunction
.get()->*i_handlerMethod
)( i_control
, i_event
) )
54 case ActivateFunction
:
55 OSL_ENSURE( false, "lcl_delegateMouseEvent: unexpected - function already *is* active!" );
57 case ContinueFunction
:
59 case DeactivateFunction
:
60 pActiveFunction
.clear();
63 furtherHandler
= true;
66 if ( !furtherHandler
)
71 // ask all other handlers
73 for (auto const& mouseFunction
: aMouseFunctions
)
77 if (mouseFunction
== pActiveFunction
)
78 // we already invoked this function
81 switch ( (mouseFunction
.get()->*i_handlerMethod
)( i_control
, i_event
) )
83 case ActivateFunction
:
84 pActiveFunction
= mouseFunction
;
87 case ContinueFunction
:
88 case DeactivateFunction
:
89 OSL_ENSURE( false, "lcl_delegateMouseEvent: unexpected: inactive handler cannot be continued or deactivated!" );
100 bool DefaultInputHandler::MouseMove( ITableControl
& i_tableControl
, const MouseEvent
& i_event
)
102 return delegateMouseEvent( i_tableControl
, i_event
, &MouseFunction::handleMouseMove
);
106 bool DefaultInputHandler::MouseButtonDown( ITableControl
& i_tableControl
, const MouseEvent
& i_event
)
108 return delegateMouseEvent( i_tableControl
, i_event
, &MouseFunction::handleMouseDown
);
112 bool DefaultInputHandler::MouseButtonUp( ITableControl
& i_tableControl
, const MouseEvent
& i_event
)
114 return delegateMouseEvent( i_tableControl
, i_event
, &MouseFunction::handleMouseUp
);
118 bool DefaultInputHandler::KeyInput( ITableControl
& _rControl
, const KeyEvent
& rKEvt
)
120 bool bHandled
= false;
122 const vcl::KeyCode
& rKeyCode
= rKEvt
.GetKeyCode();
123 sal_uInt16 nKeyCode
= rKeyCode
.GetCode();
125 struct ActionMapEntry
128 sal_uInt16 nKeyModifier
;
129 TableControlAction eAction
;
131 static const aKnownActions
[] = {
132 { KEY_DOWN
, 0, cursorDown
},
133 { KEY_UP
, 0, cursorUp
},
134 { KEY_LEFT
, 0, cursorLeft
},
135 { KEY_RIGHT
, 0, cursorRight
},
136 { KEY_HOME
, 0, cursorToLineStart
},
137 { KEY_END
, 0, cursorToLineEnd
},
138 { KEY_PAGEUP
, 0, cursorPageUp
},
139 { KEY_PAGEDOWN
, 0, cursorPageDown
},
140 { KEY_PAGEUP
, KEY_MOD1
, cursorToFirstLine
},
141 { KEY_PAGEDOWN
, KEY_MOD1
, cursorToLastLine
},
142 { KEY_HOME
, KEY_MOD1
, cursorTopLeft
},
143 { KEY_END
, KEY_MOD1
, cursorBottomRight
},
144 { KEY_SPACE
, KEY_MOD1
, cursorSelectRow
},
145 { KEY_UP
, KEY_SHIFT
, cursorSelectRowUp
},
146 { KEY_DOWN
, KEY_SHIFT
, cursorSelectRowDown
},
147 { KEY_END
, KEY_SHIFT
, cursorSelectRowAreaBottom
},
148 { KEY_HOME
, KEY_SHIFT
, cursorSelectRowAreaTop
}
150 for (const ActionMapEntry
& rAction
: aKnownActions
)
152 if ( ( rAction
.nKeyCode
== nKeyCode
) && ( rAction
.nKeyModifier
== rKeyCode
.GetModifier() ) )
154 bHandled
= _rControl
.dispatchAction( rAction
.eAction
);
163 bool DefaultInputHandler::GetFocus( ITableControl
& _rControl
)
165 _rControl
.showCursor();
166 return false; // continue processing
170 bool DefaultInputHandler::LoseFocus( ITableControl
& _rControl
)
172 _rControl
.hideCursor();
173 return false; // continue processing
177 } // namespace svt::table
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */