summaryrefslogtreecommitdiff
path: root/iup/test/timer.c
blob: f570b6329387ff031eba2e802fce29b05ea68d9d (plain)
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
#include <stdlib.h>
#include <stdio.h>
#include "iup.h"

static Ihandle *timer1, *timer2, *timer3;

static int timer_cb(Ihandle *ih)
{
  if (ih == timer1)
    printf("timer 1 called\n");

  if (ih == timer2)
  {
    printf("timer 2 called and stopped\n");
    IupSetAttribute(ih, "RUN", "NO");
  }

  if (ih == timer3)
  {
    printf("timer 3 called and CLOSE returned.\n");
    IupDestroy(timer1);
    IupDestroy(timer2);
    IupDestroy(timer3);
    return IUP_CLOSE;
  }

  return IUP_DEFAULT;
}

void TimerTest(void)
{
  Ihandle *dlg;

  dlg = IupDialog(NULL);
  IupSetAttribute(dlg, "TITLE", "IupTimer Test");
  IupSetAttribute(dlg, "SIZE", "200x100");

  IupShow(dlg);

  timer1 = IupTimer();
  timer2 = IupTimer();
  timer3 = IupTimer();

  IupSetAttribute(timer1, "TIME",  "100");
  IupSetAttribute(timer1, "RUN",   "YES");
  IupSetCallback(timer1, "ACTION_CB", (Icallback)timer_cb);

  IupSetAttribute(timer2, "TIME",  "400");
  IupSetAttribute(timer2, "RUN",   "YES");
  IupSetCallback(timer2, "ACTION_CB", (Icallback)timer_cb);

  IupSetAttribute(timer3, "TIME",  "5000");
  IupSetAttribute(timer3, "RUN",   "YES");
  IupSetCallback(timer3, "ACTION_CB", (Icallback)timer_cb);
}

#ifndef BIG_TEST
int main(int argc, char* argv[])
{
  IupOpen(&argc, &argv);

  TimerTest();

  IupMainLoop();

  IupClose();

  return EXIT_SUCCESS;
}
#endif