diff options
| author | Michael R Sweet <michael.r.sweet@gmail.com> | 2004-11-23 19:47:52 +0000 |
|---|---|---|
| committer | Michael R Sweet <michael.r.sweet@gmail.com> | 2004-11-23 19:47:52 +0000 |
| commit | a42ded75e297cedfcb448537e77d13350df0fe92 (patch) | |
| tree | 3940e35fff5db18195b113bcb5055f7c5d0577a7 /src/Fl.cxx | |
| parent | 5cc0f07c8a18841ba32ec5b3a12737c9f7d13cc2 (diff) | |
Added the 2.0 Fl_Widget::copy_label() method to allow FLTK 1.x
applications to have their label strings managed by FLTK (STR
#630)
Added Fl::delete_widget() method to safely delete widgets in
callback methods (STR #629)
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@3917 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl.cxx')
| -rw-r--r-- | src/Fl.cxx | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/src/Fl.cxx b/src/Fl.cxx index f66f63c4b..a25009101 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl.cxx,v 1.24.2.41.2.69 2004/11/23 19:09:55 easysw Exp $" +// "$Id: Fl.cxx,v 1.24.2.41.2.70 2004/11/23 19:47:51 easysw Exp $" // // Main event handling code for the Fast Light Tool Kit (FLTK). // @@ -236,6 +236,8 @@ extern int fl_wait(double time); // in Fl_<platform>.cxx static char in_idle; double Fl::wait(double time_to_wait) { + do_widget_deletions(); + if (first_timeout) { elapse_timeouts(); Timeout *t; @@ -1051,6 +1053,48 @@ void Fl_Window::flush() { draw(); } + +// +// The following methods allow callbacks to schedule the deletion of +// widgets at "safe" times. +// + +static int num_dwidgets = 0, alloc_dwidgets = 0; +static Fl_Widget **dwidgets = 0; + +void +Fl::delete_widget(Fl_Widget *w) { + if (!w) return; + + if (num_dwidgets >= alloc_dwidgets) { + Fl_Widget **temp; + + temp = new Fl_Widget *[alloc_dwidgets + 10]; + if (alloc_dwidgets) { + memcpy(temp, dwidgets, alloc_dwidgets * sizeof(Fl_Widget *)); + delete[] dwidgets; + } + + dwidgets = temp; + alloc_dwidgets += 10; + } + + dwidgets[num_dwidgets] = w; + num_dwidgets ++; +} + + +void +Fl::do_widget_deletion() { + if (!num_dwidgets) return; + + for (int i = 0; i < num_dwidgets; i ++) + delete dwidgets[i]; + + num_dwidgets = 0; +} + + // -// End of "$Id: Fl.cxx,v 1.24.2.41.2.69 2004/11/23 19:09:55 easysw Exp $". +// End of "$Id: Fl.cxx,v 1.24.2.41.2.70 2004/11/23 19:47:51 easysw Exp $". // |
