fltk_timer.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:4k
- /*
- * ===========================================================================
- * PRODUCTION $Log: fltk_timer.cpp,v $
- * PRODUCTION Revision 1000.0 2004/06/01 21:29:11 gouriano
- * PRODUCTION PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.2
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: fltk_timer.cpp,v 1000.0 2004/06/01 21:29:11 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software/database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software/database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Andrey Yazhuk
- *
- */
- //#include <corelib/ncbistd.hpp>
- #include <ncbi_pch.hpp>
- #include <gui/widgets/fl/fltk_timer.hpp>
- #include <FL/Fl.H>
- BEGIN_NCBI_SCOPE
- CFLTKTimer::CFLTKTimer()
- {
- Init(0, 1.0, NULL, false);
- }
- CFLTKTimer::CFLTKTimer(int id, double period, bool repeat, ITimerListener* listener)
- {
- Init(id, period, repeat, listener);
- }
- void CFLTKTimer::Init(int id, double period, bool repeat, ITimerListener* listener)
- {
- m_ID = id;
- m_Period = period;
- m_Repeat = repeat;
- m_Running = false;
- m_Listener = listener;
- }
- CFLTKTimer::~CFLTKTimer()
- {
- Stop();
- }
- void CFLTKTimer::SetListener(ITimerListener* listener)
- {
- m_Listener = listener;
- }
- void CFLTKTimer::Start()
- {
- if(!m_Running && m_Listener) {
- m_Running = true;
- void* data = reinterpret_cast<void*>(this);
- Fl::add_timeout(m_Period, x_OnTimeout, data);
- } else _ASSERT(false);
- }
- void CFLTKTimer::StartOnce()
- {
- m_Repeat = false;
- Start();
- }
- void CFLTKTimer::Stop()
- {
- if(m_Running) {
- void* data = reinterpret_cast<void*>(this);
- Fl::remove_timeout(x_OnTimeout, data);
- m_Running = false;
- }
- }
- void CFLTKTimer::ReStart()
- {
- Stop();
- Start();
- }
- bool CFLTKTimer::IsRunning()
- {
- return m_Running;
- }
- void CFLTKTimer::x_OnTimeout(void* data)
- {
- CFLTKTimer* timer = reinterpret_cast<CFLTKTimer*>(data);
- timer->m_Listener->OnTimeout(timer->m_ID);
- if(timer->m_Repeat) {
- Fl::repeat_timeout(timer->m_Period, x_OnTimeout, data); //continue
- } else {
- timer->m_Running = false;
- }
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: fltk_timer.cpp,v $
- * Revision 1000.0 2004/06/01 21:29:11 gouriano
- * PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.2
- *
- * Revision 1.2 2004/05/21 22:27:53 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.1 2004/05/03 19:44:24 yazhuk
- * Initial revision
- *
- * ===========================================================================
- */