diff options
author | Pixel <pixel@nobis-crew.org> | 2009-11-04 11:56:41 -0800 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2009-11-04 11:59:33 -0800 |
commit | d577d991b97ae2b5ee1af23641bcffc3f83af5b2 (patch) | |
tree | 590639d50205d1bcfaff2a7d2dc6ebf3f373c7ed /iup/src/mot/iupmot_loop.c |
Initial import. Contains the im, cd and iup librairies, and a "working" Makefile for them under linux.
Diffstat (limited to 'iup/src/mot/iupmot_loop.c')
-rwxr-xr-x | iup/src/mot/iupmot_loop.c | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/iup/src/mot/iupmot_loop.c b/iup/src/mot/iupmot_loop.c new file mode 100755 index 0000000..828ddcd --- /dev/null +++ b/iup/src/mot/iupmot_loop.c @@ -0,0 +1,108 @@ +/** \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 motLoopStep(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 (motLoopStep() == IUP_CLOSE) + break; + } + + mot_exitmainloop = 0; + mot_mainloop--; + return IUP_NOERROR; +} + +int IupLoopStep(void) +{ + if (!XtAppPending(iupmot_appcontext)) + return IUP_DEFAULT; + + return motLoopStep(); +} + +void IupFlush(void) +{ + while (XPending(iupmot_display) != 0) + { + if (motLoopStep() == IUP_CLOSE) + break; + } + + XFlush(iupmot_display); +} |