blob: c1f92ec618b8f4daaa951e02fa631efa9061f903 (
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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/** \file
* \brief Motif Message Loop
*
* See Copyright Notice in "iup.h"
*/
#include <stdio.h>
#include <Xm/Xm.h>
#include "iup.h"
#include "iupcbs.h"
#include "iupmot_drv.h"
/* local variables */
static int mot_mainloop = 0;
static int mot_exitmainloop = 0;
static IFidle mot_idle_cb = NULL;
static XtWorkProcId mot_idle_id;
static Boolean motIdlecbWorkProc(XtPointer client_data)
{
(void)client_data;
if (mot_idle_cb)
{
int ret = mot_idle_cb();
if (ret == IUP_CLOSE)
{
mot_idle_cb = NULL;
IupExitLoop();
return True; /* removes the working procedure */
}
if (ret == IUP_IGNORE)
{
mot_idle_cb = NULL;
return True; /* removes the working procedure */
}
return False; /* keeps the working procedure */
}
return True; /* removes the working procedure */
}
void iupdrvSetIdleFunction(Icallback f)
{
if (mot_idle_cb)
XtRemoveWorkProc(mot_idle_id);
mot_idle_cb = (IFidle)f;
if (mot_idle_cb)
mot_idle_id = XtAppAddWorkProc(iupmot_appcontext, motIdlecbWorkProc, NULL);
}
static int motLoopProcessEvent(void)
{
XtAppProcessEvent(iupmot_appcontext, XtIMAll);
return (mot_exitmainloop)? IUP_CLOSE : IUP_DEFAULT;
}
void IupExitLoop(void)
{
mot_exitmainloop = 1;
}
int IupMainLoopLevel(void)
{
return mot_mainloop;
}
int IupMainLoop(void)
{
mot_mainloop++;
mot_exitmainloop = 0;
while (!mot_exitmainloop)
{
if (motLoopProcessEvent() == IUP_CLOSE)
break;
}
mot_exitmainloop = 0;
mot_mainloop--;
return IUP_NOERROR;
}
int IupLoopStepWait(void)
{
while(!XtAppPending(iupmot_appcontext));
return motLoopProcessEvent();
}
int IupLoopStep(void)
{
if (!XtAppPending(iupmot_appcontext))
return IUP_DEFAULT;
return motLoopProcessEvent();
}
void IupFlush(void)
{
while (XPending(iupmot_display) != 0)
{
if (motLoopProcessEvent() == IUP_CLOSE)
break;
}
XFlush(iupmot_display);
}
|