File: vtimer.cpp

package info (click to toggle)
libv1.22 1.22-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,380 kB
  • ctags: 9,765
  • sloc: cpp: 58,097; ansic: 6,814; makefile: 1,597; java: 515; sh: 24
file content (101 lines) | stat: -rw-r--r-- 2,569 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//===============================================================
// vTimer.cxx - vTimer class functions - Windows
//
// Copyright (C) 1995,1996, 1997, 1998  Bruce E. Wampler
//
// This file is part of the V C++ GUI Framework, and is covered
// under the terms of the GNU Library General Public License,
// Version 2. This library has NO WARRANTY. See the source file
// vapp.cxx for more complete information about license terms.
//===============================================================

#include <v/vwin32.h>		// for Win 32 stuff
#include <v/vapp.h>
#include <v/vtimer.h>
#include <v/vthislst.h>

// Define static data of the class

  void CALLBACK vTimerProc(HWND /*hwnd*/, UINT msg, UINT idTimer, DWORD /*dwTime*/);

  static vThisList _timers;

//=========================>>> vTimer::vTimerProc <<<=======================
  void CALLBACK vTimerProc(HWND hwnd, UINT msg, UINT idTimer, DWORD dwTime)
  {
    if (msg != WM_TIMER)
	return;			// ignore...

    vTimer* mytime = (vTimer*) _timers.GetThis((ThisId)idTimer);
    if (mytime)			// Make sure we got a this
	mytime->tick();
  }

//======================>>> vTimer::vTimer <<<=======================
  vTimer::vTimer( )		// default constructor
  {
    SysDebug(Constructor,"vTimer::vTimer - constructor\n");

    _id = 0;			// no id
    _interval = 0;		// no interval
  }

//======================>>> vTimer::~vTimer <<<=======================
  vTimer::~vTimer( )
  {
    SysDebug(Destructor,"vTimer::~vTimer - destructor\n");

    if (_id)			// remove timer if in effect
      {
	TimerStop();
      }
  }

//======================>>> vTimer::TimerSet <<<=======================
  int vTimer::TimerSet(long interval)
  {

    if (_id)			// remove timer if in effect
      {
	TimerStop();
      }

    _interval = interval;

    _id = (HWND) ::SetTimer(0,0, interval, (TIMERPROC)vTimerProc);

    if (_id != 0)
      {
	_timers.Add((ThisId)_id, (void*)this);
	return 1;
      }
    else
	return 0;

  }

//======================>>> vTimer::TimerStop <<<=======================
  void vTimer::TimerStop(void)
  {
    if (_id)			// remove timer if in effect
      {
	::KillTimer(_id, 0);
	_timers.Delete((ThisId)_id);	// delete old timer
	_id = 0;
      }
  }

//======================>>> vTimer::TimerTick <<<=======================
  void vTimer::TimerTick(void)
  {
    // default has no action - will be overridden
  }

//=========================>>> vTimer::tick <<<=======================
  void vTimer::tick(void)
  {
    // internal tick routine

    TimerTick();		// call the work routine
  }