summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2006-01-02 10:31:59 +0000
committerMatthias Melcher <fltk@matthiasm.com>2006-01-02 10:31:59 +0000
commit67bc851abbd56ffcb8bb5ce9083485acf9560b00 (patch)
tree43a99c21eb844542735db59c38fd0f7ae02fa36f /src
parent3e1666448de7f49e722f86ddfd9175fca358ba6d (diff)
STR #1135: Triggering a timout would not break the event loop, giving no opportunity to FLTK to call flush. As a result, all redrawing that depended on timeouts only would not get done unless some other event was received. If the idle function was set, the event loop would break and redraw wold work again.
I moved all timeout functions from Fl.cxx to Fl_mac.cxx since they are very system specific and made the timeout break the main event loop, just like it does on all other platforms. This bug must have been around for at least two months... . git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4730 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl.cxx100
-rw-r--r--src/Fl_mac.cxx100
2 files changed, 101 insertions, 99 deletions
diff --git a/src/Fl.cxx b/src/Fl.cxx
index 2492c5050..bb7cee968 100644
--- a/src/Fl.cxx
+++ b/src/Fl.cxx
@@ -116,105 +116,7 @@ int Fl::event_inside(const Fl_Widget *o) /*const*/ {
#elif defined(__APPLE__)
-//
-// MacOS X timers
-//
-
-struct MacTimeout {
- Fl_Timeout_Handler callback;
- void* data;
- EventLoopTimerRef timer;
-};
-static MacTimeout* mac_timers;
-static int mac_timer_alloc;
-static int mac_timer_used;
-
-
-static void realloc_timers()
-{
- if (mac_timer_alloc == 0) {
- mac_timer_alloc = 8;
- }
- MacTimeout* new_timers = new MacTimeout[mac_timer_alloc * 2];
- memmove(new_timers, mac_timers, sizeof(MacTimeout) * mac_timer_used);
- MacTimeout* delete_me = mac_timers;
- mac_timers = new_timers;
- delete [] delete_me;
- mac_timer_alloc *= 2;
-}
-
-static void delete_timer(MacTimeout& t)
-{
- RemoveEventLoopTimer(t.timer);
- memset(&t, 0, sizeof(MacTimeout));
-}
-
-
-static pascal void do_timer(EventLoopTimerRef timer, void* data)
-{
- for (int i = 0; i < mac_timer_used; ++i) {
- MacTimeout& t = mac_timers[i];
- if (t.timer == timer && t.data == data) {
- return (*t.callback)(data);
- }
- }
-}
-
-
-void Fl::add_timeout(double time, Fl_Timeout_Handler cb, void* data)
-{
- int timer_id = -1;
- for (int i = 0; i < mac_timer_used; ++i) {
- if ( !mac_timers[i].timer ) {
- timer_id = i;
- break;
- }
- }
- if (timer_id == -1) {
- if (mac_timer_used == mac_timer_alloc) {
- realloc_timers();
- }
- timer_id = mac_timer_used++;
- }
-
- EventTimerInterval fireDelay = (EventTimerInterval) time;
- EventLoopTimerUPP timerUPP = NewEventLoopTimerUPP(do_timer);
- EventLoopTimerRef timerRef;
- OSStatus err = InstallEventLoopTimer(GetMainEventLoop(), fireDelay, 0, timerUPP, data, &timerRef);
- if (err == noErr) {
- mac_timers[timer_id].callback = cb;
- mac_timers[timer_id].data = data;
- mac_timers[timer_id].timer = timerRef;
- }
-}
-
-void Fl::repeat_timeout(double time, Fl_Timeout_Handler cb, void* data)
-{
- remove_timeout(cb, data);
- add_timeout(time, cb, data);
-}
-
-int Fl::has_timeout(Fl_Timeout_Handler cb, void* data)
-{
- for (int i = 0; i < mac_timer_used; ++i) {
- MacTimeout& t = mac_timers[i];
- if (t.callback == cb && t.data == data) {
- return 1;
- }
- }
- return 0;
-}
-
-void Fl::remove_timeout(Fl_Timeout_Handler cb, void* data)
-{
- for (int i = 0; i < mac_timer_used; ++i) {
- MacTimeout& t = mac_timers[i];
- if (t.callback == cb && ( t.data == data || data == NULL)) {
- delete_timer(t);
- }
- }
-}
-
+/// implementation in Fl_mac.cxx
#else
diff --git a/src/Fl_mac.cxx b/src/Fl_mac.cxx
index 2338fd421..606570b69 100644
--- a/src/Fl_mac.cxx
+++ b/src/Fl_mac.cxx
@@ -599,6 +599,51 @@ static void breakMacEventLoop()
fl_unlock_function();
}
+//
+// MacOS X timers
+//
+
+struct MacTimeout {
+ Fl_Timeout_Handler callback;
+ void* data;
+ EventLoopTimerRef timer;
+};
+static MacTimeout* mac_timers;
+static int mac_timer_alloc;
+static int mac_timer_used;
+
+
+static void realloc_timers()
+{
+ if (mac_timer_alloc == 0) {
+ mac_timer_alloc = 8;
+ }
+ MacTimeout* new_timers = new MacTimeout[mac_timer_alloc * 2];
+ memmove(new_timers, mac_timers, sizeof(MacTimeout) * mac_timer_used);
+ MacTimeout* delete_me = mac_timers;
+ mac_timers = new_timers;
+ delete [] delete_me;
+ mac_timer_alloc *= 2;
+}
+
+static void delete_timer(MacTimeout& t)
+{
+ RemoveEventLoopTimer(t.timer);
+ memset(&t, 0, sizeof(MacTimeout));
+}
+
+
+static pascal void do_timer(EventLoopTimerRef timer, void* data)
+{
+ for (int i = 0; i < mac_timer_used; ++i) {
+ MacTimeout& t = mac_timers[i];
+ if (t.timer == timer && t.data == data) {
+ (*t.callback)(data);
+ break;
+ }
+ }
+ breakMacEventLoop();
+}
/**
* This function is the central event handler.
@@ -2136,6 +2181,61 @@ void Fl::paste(Fl_Widget &receiver, int clipboard) {
return;
}
+void Fl::add_timeout(double time, Fl_Timeout_Handler cb, void* data)
+{
+ int timer_id = -1;
+ for (int i = 0; i < mac_timer_used; ++i) {
+ if ( !mac_timers[i].timer ) {
+ timer_id = i;
+ break;
+ }
+ }
+ if (timer_id == -1) {
+ if (mac_timer_used == mac_timer_alloc) {
+ realloc_timers();
+ }
+ timer_id = mac_timer_used++;
+ }
+
+ EventTimerInterval fireDelay = (EventTimerInterval) time;
+ EventLoopTimerUPP timerUPP = NewEventLoopTimerUPP(do_timer);
+ EventLoopTimerRef timerRef;
+ OSStatus err = InstallEventLoopTimer(GetMainEventLoop(), fireDelay, 0, timerUPP, data, &timerRef);
+ if (err == noErr) {
+ mac_timers[timer_id].callback = cb;
+ mac_timers[timer_id].data = data;
+ mac_timers[timer_id].timer = timerRef;
+ }
+}
+
+void Fl::repeat_timeout(double time, Fl_Timeout_Handler cb, void* data)
+{
+ remove_timeout(cb, data);
+ add_timeout(time, cb, data);
+}
+
+int Fl::has_timeout(Fl_Timeout_Handler cb, void* data)
+{
+ for (int i = 0; i < mac_timer_used; ++i) {
+ MacTimeout& t = mac_timers[i];
+ if (t.callback == cb && t.data == data) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+void Fl::remove_timeout(Fl_Timeout_Handler cb, void* data)
+{
+ for (int i = 0; i < mac_timer_used; ++i) {
+ MacTimeout& t = mac_timers[i];
+ if (t.callback == cb && ( t.data == data || data == NULL)) {
+ delete_timer(t);
+ }
+ }
+}
+
+
//
// End of "$Id$".