1
// ButtonMultiPress.cpp
3
// Copyright (c) 2007 The Dasher Team
5
// This file is part of Dasher.
7
// Dasher is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
12
// Dasher is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
// You should have received a copy of the GNU General Public License
18
// along with Dasher; if not, write to the Free Software
19
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "DasherInterfaceBase.h"
22
#include "ButtonMultiPress.h"
24
using namespace Dasher;
26
CButtonMultiPress::CButtonMultiPress(Dasher::CEventHandler * pEventHandler, CSettingsStore *pSettingsStore, CDasherInterfaceBase *pInterface, ModuleID_t iID, int iType, const char *szName)
27
: CDynamicFilter(pEventHandler, pSettingsStore, pInterface, iID, iType, szName) {
30
void CButtonMultiPress::KeyDown(int iTime, int iId, CDasherView *pView, CDasherModel *pModel, CUserLogBase *pUserLog) {
32
if (m_bKeyDown) return;
34
// Check for multiple clicks
35
if(iId == m_iQueueId && m_deQueueTimes.size()) {
36
if ( (iTime - m_deQueueTimes.back()) > GetLongParameter(LP_MULTIPRESS_TIME) )
37
m_deQueueTimes.clear(); //and fall through to record+process normally, below
40
//previous presses should not be treated as such....
41
RevertPresses(m_deQueueTimes.size());
42
//...but should be combined with this one into a new event (type = #presses)
43
Event(iTime, iId, m_deQueueTimes.size()+1, pModel, pUserLog);
44
if (m_deQueueTimes.size() >= maxClickCount() - 1)
45
m_deQueueTimes.clear(); //final press
46
else //may still be more presses to come
47
m_deQueueTimes.push_back(iTime);
48
return; //we've called Event ourselves, so finished.
53
m_deQueueTimes.clear(); //clear record of previous, different, button
58
m_deQueueTimes.push_back(iTime);
59
// ... and process normally; if it changes the state, pause()/reverse()'ll clear the queue
60
CDynamicFilter::KeyDown(iTime, iId, pView, pModel, pUserLog);
63
void CButtonMultiPress::pause()
65
CDynamicFilter::pause();
66
m_deQueueTimes.clear();
69
void CButtonMultiPress::reverse()
71
CDynamicFilter::reverse();
72
m_deQueueTimes.clear();
75
void CButtonMultiPress::run()
77
if (!isRunning()) m_deQueueTimes.clear();
78
CDynamicFilter::run();