Debian Codegraph @

toolkit/source/controls/table/defaultinputhandler.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <controls/table/defaultinputhandler.hxx>
21 #include <controls/table/tablecontrolinterface.hxx>
22
23 #include <vcl/event.hxx>
24 #include <osl/diagnose.h>
25
26 namespace svt::table
27 {
28
29
30 //= DefaultInputHandler
31
32
33 DefaultInputHandler::DefaultInputHandler()
34 {
35 aMouseFunctions.push_back( new ColumnResize );
36 aMouseFunctions.push_back( new RowSelection );
37 aMouseFunctions.push_back( new ColumnSortHandler );
38 }
39
40
41 DefaultInputHandler::~DefaultInputHandler()
42 {
43 }
44
45
46 bool DefaultInputHandler::delegateMouseEvent( ITableControl& i_control, const MouseEvent& i_event,
47 FunctionResult ( MouseFunction::*i_handlerMethod )( ITableControl&, const MouseEvent& ) )
48 {
49 if ( pActiveFunction.is() )
50 {
51 bool furtherHandler = false;
52 switch ( (pActiveFunction.get()->*i_handlerMethod)( i_control, i_event ) )
53 {
54 case ActivateFunction:
55 OSL_ENSURE( false, "lcl_delegateMouseEvent: unexpected - function already *is* active!" );
56 break;
57 case ContinueFunction:
58 break;
59 case DeactivateFunction:
60 pActiveFunction.clear();
61 break;
62 case SkipFunction:
63 furtherHandler = true;
64 break;
65 }
66 if ( !furtherHandler )
67 // handled the event
68 return true;
69 }
70
71 // ask all other handlers
72 bool handled = false;
73 for (auto const& mouseFunction : aMouseFunctions)
74 {
75 if (handled)
76 break;
77 if (mouseFunction == pActiveFunction)
78 // we already invoked this function
79 continue;
80
81 switch ( (mouseFunction.get()->*i_handlerMethod)( i_control, i_event ) )
82 {
83 case ActivateFunction:
84 pActiveFunction = mouseFunction;
85 handled = true;
86 break;
87 case ContinueFunction:
88 case DeactivateFunction:
89 OSL_ENSURE( false, "lcl_delegateMouseEvent: unexpected: inactive handler cannot be continued or deactivated!" );
90 break;
91 case SkipFunction:
92 handled = false;
93 break;
94 }
95 }
96 return handled;
97 }
98
99
100 bool DefaultInputHandler::MouseMove( ITableControl& i_tableControl, const MouseEvent& i_event )
101 {
102 return delegateMouseEvent( i_tableControl, i_event, &MouseFunction::handleMouseMove );
103 }
104
105
106 bool DefaultInputHandler::MouseButtonDown( ITableControl& i_tableControl, const MouseEvent& i_event )
107 {
108 return delegateMouseEvent( i_tableControl, i_event, &MouseFunction::handleMouseDown );
109 }
110
111
112 bool DefaultInputHandler::MouseButtonUp( ITableControl& i_tableControl, const MouseEvent& i_event )
113 {
114 return delegateMouseEvent( i_tableControl, i_event, &MouseFunction::handleMouseUp );
115 }
116
117 } // namespace svt::table
118
119
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */