home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
yacl-012.zip
/
ui
/
timer.cxx
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-04
|
3KB
|
147 lines
#if defined(__GNUC__)
#pragma implementation
#endif
#include "base/set.h"
#include "ui/timer.h"
#include "ui/applic.h"
#include "ui/cntroler.h"
#if defined(__UNIX__)
#include <sys/time.h>
#endif
#if defined(__MS_WINDOWS__)
#include <windows.h>
static CL_IntPtrMap _TimerMap; // Map of Windows timer indices to
// UI_Timer objects
WORD FAR PASCAL TimerFunc (HWND, WORD, int id, DWORD)
{
UI_Timer* tmr = (UI_Timer*) _TimerMap[id];
if (tmr)
tmr->DoAlarm();
return 0;
}
#elif defined(__OS2__)
CL_IntPtrMap UI_Timer::_TimerMap;
#endif
UI_Timer::UI_Timer (const CL_AbstractBinding& bnd)
{
_bind = (CL_AbstractBinding*) bnd.Clone();
#if defined(__MS_WINDOWS__)
_id = 0;
#endif
}
UI_Timer::~UI_Timer ()
{
Stop();
#if defined(__OS2__)
_TimerMap.Remove (_id);
#endif
delete _bind;
}
bool UI_Timer::Start (long msecs)
{
_msecs = msecs;
#if defined(__MS_WINDOWS__)
if (!_TheApplication)
return FALSE;
long n = _TimerMap.Size()+1;
if (SetTimer (_TheApplication->MainWindow()->ViewHandle(),
n, msecs, (FARPROC) TimerFunc)) {
_id = n;
_TimerMap.Add (n, this);
_running = TRUE;
return TRUE;
}
return FALSE;
#elif defined(__OS2__)
_id = WinStartTimer (_TheApplication->Controller().AnchorBlockHandle(),
NULLHANDLE, 0, msecs);
_TimerMap.Add (_id, this);
_running = TRUE;
return TRUE;
#elif defined(__UNIX__)
if (!_TheApplication)
return FALSE;
_id = _TheApplication->Controller().RegisterTimeOut
(msecs, &UI_Timer::DoAlarm, this);
if (_id) {
_running = TRUE;
return TRUE;
}
return FALSE;
#endif
}
bool UI_Timer::Stop ()
{
#if defined(__MS_WINDOWS__)
if (_id > 0) {
KillTimer (NULL, _id);
_TimerMap.Remove (_id);
_id = 0;
return TRUE;
}
return FALSE;
#elif defined(__OS2__)
if (_running)
WinStopTimer (_TheApplication->Controller().AnchorBlockHandle(),
NULLHANDLE, _id);
return TRUE;
#elif defined(__X_MOTIF__)
if (_TheApplication && _running) {
_TheApplication->Controller().UnregisterTimeOut (_id);
_running = FALSE;
}
#endif
}
#if defined(__MS_WINDOWS__)
void UI_Timer::DoAlarm ()
{
if (_id >= 1 && _running)
_bind->Execute (*this, _id);
}
#elif defined(__X_MOTIF__)
void UI_Timer::DoAlarm (void* p, ulong* id)
{
UI_Timer* tmr = (UI_Timer*) p;
if (tmr && tmr->_bind && tmr->_running) {
tmr->_bind->Execute (*tmr, *id);
tmr->_id = _TheApplication->Controller().RegisterTimeOut
(tmr->_msecs, &UI_Timer::DoAlarm, tmr);
}
}
#elif defined(__OS2__)
void UI_Timer::DoAlarm (ulong id)
{
UI_Timer* t = (UI_Timer*) _TimerMap [id];
if (t)
t->_bind->Execute (*t, id);
}
#endif