summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES5
-rw-r--r--FL/Fl.H8
-rw-r--r--FL/Fl_Widget.H9
-rw-r--r--documentation/Fl.html11
-rw-r--r--documentation/Fl_Widget.html16
-rw-r--r--documentation/common.html11
-rw-r--r--documentation/index.html6
-rw-r--r--documentation/preface.html6
-rw-r--r--src/Fl.cxx48
-rw-r--r--src/Fl_Widget.cxx26
10 files changed, 127 insertions, 19 deletions
diff --git a/CHANGES b/CHANGES
index 45a7fce3a..1d8251b35 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,11 @@
CHANGES IN FLTK 1.1.6
- Documentation updates (STR #552, STR #608)
+ - 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)
- Fl_Widget::damage(uchar,int,int,int,int) didn't clip
the bounding box properly (STR #626)
- Windows could appear on the wrong screen on OSX (STR
diff --git a/FL/Fl.H b/FL/Fl.H
index d0f65683c..9971de1de 100644
--- a/FL/Fl.H
+++ b/FL/Fl.H
@@ -1,5 +1,5 @@
//
-// "$Id: Fl.H,v 1.8.2.11.2.23 2004/04/11 04:38:53 easysw Exp $"
+// "$Id: Fl.H,v 1.8.2.11.2.24 2004/11/23 19:47:50 easysw Exp $"
//
// Main header file for the Fast Light Tool Kit (FLTK).
//
@@ -257,10 +257,14 @@ public:
static void unlock();
static void awake(void* message = 0);
static void* thread_message();
+
+ // Widget deletion:
+ static void delete_widget(Fl_Widget *w);
+ static void do_widget_deletion();
};
#endif // !Fl_H
//
-// End of "$Id: Fl.H,v 1.8.2.11.2.23 2004/04/11 04:38:53 easysw Exp $".
+// End of "$Id: Fl.H,v 1.8.2.11.2.24 2004/11/23 19:47:50 easysw Exp $".
//
diff --git a/FL/Fl_Widget.H b/FL/Fl_Widget.H
index 7fed7af76..e33e1d47d 100644
--- a/FL/Fl_Widget.H
+++ b/FL/Fl_Widget.H
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Widget.H,v 1.6.2.4.2.25 2004/09/24 16:00:08 easysw Exp $"
+// "$Id: Fl_Widget.H,v 1.6.2.4.2.26 2004/11/23 19:47:50 easysw Exp $"
//
// Widget header file for the Fast Light Tool Kit (FLTK).
//
@@ -90,7 +90,7 @@ protected:
void set_flag(int c) {flags_ |= c;}
void clear_flag(int c) {flags_ &= ~c;}
enum {INACTIVE=1, INVISIBLE=2, OUTPUT=4, SHORTCUT_LABEL=64,
- CHANGED=128, VISIBLE_FOCUS=512};
+ CHANGED=128, VISIBLE_FOCUS=512, COPIED_LABEL = 1024};
void draw_box() const;
void draw_box(Fl_Boxtype, Fl_Color) const;
@@ -131,7 +131,8 @@ public:
void selection_color(unsigned a) {color2_ = a;}
void color(unsigned a, unsigned b) {color_=a; color2_=b;}
const char* label() const {return label_.value;}
- void label(const char* a) {label_.value=a; redraw_label();}
+ void label(const char* a);
+ void copy_label(const char* a);
void label(Fl_Labeltype a,const char* b) {label_.type = a; label_.value = b;}
Fl_Labeltype labeltype() const {return (Fl_Labeltype)label_.type;}
void labeltype(Fl_Labeltype a) {label_.type = a;}
@@ -217,5 +218,5 @@ public:
#endif
//
-// End of "$Id: Fl_Widget.H,v 1.6.2.4.2.25 2004/09/24 16:00:08 easysw Exp $".
+// End of "$Id: Fl_Widget.H,v 1.6.2.4.2.26 2004/11/23 19:47:50 easysw Exp $".
//
diff --git a/documentation/Fl.html b/documentation/Fl.html
index 5e34d8394..96791f3d3 100644
--- a/documentation/Fl.html
+++ b/documentation/Fl.html
@@ -49,6 +49,7 @@ state information and global methods for the current application.</P>
<LI><A HREF="#Fl.copy">copy</A></LI>
<LI><A HREF="#Fl.damage">damage</A></LI>
<LI><A HREF="#Fl.default_atclose">default_atclose</A></LI>
+ <LI><A HREF="#Fl.delete_widget">delete_widget</A></LI>
<LI><A HREF="#Fl.display">display</A></LI>
<LI><A HREF="#Fl.dnd">dnd</A></LI>
<LI><A HREF="#Fl.dnd_text_ops">dnd_text_ops</A></LI>
@@ -491,6 +492,16 @@ void damage(int x);</A></H4>
<H4><A NAME="Fl.default_atclose">void default_atclose(Fl_Window*,void*);</A></H4>
+<p>This is the default callback for window widgets. It hides the
+window and then calls the default widget callback.</p>
+
+<H4><A NAME="Fl.delete_widget">void delete_widget(Fl_Widget*);</A></H4>
+
+<p>Schedules a widget for deletion when it is safe to do so. Use
+this method to delete a widget inside a callback function. When
+deleting groups or windows, you must only delete the group or
+window widget and not the individual child widgets.</p>
+
<H4><A NAME="Fl.display">void display(const char*);</A></H4>
<P>Sets the X display to use for all windows. Actually this just sets
diff --git a/documentation/Fl_Widget.html b/documentation/Fl_Widget.html
index f7e0e09e5..179693959 100644
--- a/documentation/Fl_Widget.html
+++ b/documentation/Fl_Widget.html
@@ -53,6 +53,7 @@ to call <TT>redraw()</TT> after these. </P>
<UL>
<LI><A href=#Fl_Widget.color>color</A></LI>
<LI><A href=#Fl_Widget.contains>contains</A></LI>
+<LI><A href=#Fl_Widget.copy_label>copy_label</A></LI>
<LI><A href=#Fl_Widget.damage>damage</A></LI>
<LI><A href=#Fl_Widget.deactivate>deactivate</A></LI>
<LI><A href=#Fl_Widget.default_callback>default_callback</A></LI>
@@ -64,10 +65,10 @@ to call <TT>redraw()</TT> after these. </P>
<LI><A href=#Fl_Widget.image>image</A></LI>
<LI><A href=#Fl_Widget.inside>inside</A></LI>
<LI><A href=#Fl_Widget.label>label</A></LI>
-<LI><A href=#Fl_Widget.labelcolor>labelcolor</A></LI>
</UL>
</TD><TD align=left valign=top>
<UL>
+<LI><A href=#Fl_Widget.labelcolor>labelcolor</A></LI>
<LI><A href=#Fl_Widget.labelfont>labelfont</A></LI>
<LI><A href=#Fl_Widget.labelsize>labelsize</A></LI>
<LI><A href=#Fl_Widget.labeltype>labeltype</A></LI>
@@ -258,6 +259,14 @@ method for more information.
equal to this widget. Returns 0 if <TT>b</TT> is <TT>NULL</TT>.
+<H4><A name='Fl_Widget.copy_label'>void Fl_Widget::copy_label(const char*)</A></H4>
+
+<P>Sets the current label. Unlike <a
+href='#Fl_Widget.label'><tt>label()</tt></a>, this method
+allocates a copy of the label string instead of using the
+original string pointer.</p>
+
+
<H4><A name=Fl_Widget.damage>uchar Fl_Widget::damage() const<BR>
void damage(uchar c);<BR>
void damage(uchar c, int X, int Y, int W, int H);</A></H4>
@@ -329,7 +338,10 @@ equal to <TT>a</TT>. Returns 0 if <TT>a</TT> is <TT>NULL</TT>.
somewhere on or next to the widget. The passed pointer is stored
unchanged in the widget (the string is <I>not</I> copied), so if
you need to set the label to a formatted value, make sure the
-buffer is <TT>static</TT>, global, or allocated.
+buffer is <TT>static</TT>, global, or allocated. The <a
+href='#Fl_Widget.copy_label'><tt>copy_label()</tt></a> method
+can be used to make a copy of the label string
+automatically.</p>
<H4><A name=Fl_Widget.labelcolor>Fl_Color Fl_Widget::labelcolor() const
diff --git a/documentation/common.html b/documentation/common.html
index 85d091138..a7f17fca5 100644
--- a/documentation/common.html
+++ b/documentation/common.html
@@ -532,7 +532,16 @@ button-&gt;when(FL_WHEN_CHANGED | FL_WHEN_NOT_CHANGED);
<CENTER><TABLE WIDTH="80%" BORDER="1" CELLPADDING="5" CELLSPACING="0" BGCOLOR="#cccccc">
<TR>
- <TD><B>Hint:</B>
+ <TD><B>Note:</B>
+
+ <P>You cannot delete a widget inside a callback, as the
+ widget may still be accessed by FLTK after your callback
+ is completed. Instead, use the <a
+ href='Fl.html#Fl.delete_widget'><tt>Fl::delete_widget()</tt></a>
+ method to mark your widget for deletion when it is safe
+ to do so.</p>
+
+ <p><B>Hint:</B>
<P>Many programmers new to FLTK or C++ try to use a
non-static class method instead of a static class method
diff --git a/documentation/index.html b/documentation/index.html
index 97bd3e884..2853526ba 100644
--- a/documentation/index.html
+++ b/documentation/index.html
@@ -1,7 +1,7 @@
<HTML>
<HEAD>
<META NAME="robots" CONTENT="noindex">
- <TITLE>FLTK 1.1.5 Programming Manual</TITLE>
+ <TITLE>FLTK 1.1.6 Programming Manual</TITLE>
</HEAD>
<BODY>
@@ -10,8 +10,8 @@
<TD VALIGN="MIDDLE">
<IMG SRC="FL.gif" WIDTH="200" HEIGHT="100" ALIGN="ABSMIDDLE" ALT="FL"></TD>
<TD ALIGN="CENTER" VALIGN="MIDDLE">
- <H1>FLTK 1.1.5 Programming Manual</H1>
- <P>Revision 5 by Michael Sweet, Craig P. Earls, and Bill Spitzak<BR>
+ <H1>FLTK 1.1.6 Programming Manual</H1>
+ <P>Revision 6 by Michael Sweet, Craig P. Earls, and Bill Spitzak<BR>
Copyright 1998-2004 by Bill Spitzak and others.</P>
</TD>
</TR>
diff --git a/documentation/preface.html b/documentation/preface.html
index c773fa575..a53e8899d 100644
--- a/documentation/preface.html
+++ b/documentation/preface.html
@@ -2,15 +2,15 @@
<HEAD>
<META CONTENT="Written by Michael Sweet, Craig P. Earls, and Bill Spitzak" NAME="Author">
<META CONTENT="Copyright 1998-2004 by Bill Spitzak and Others." NAME="Copyright">
- <META CONTENT="Revision 5" NAME="DocNumber">
- <TITLE>FLTK 1.1.5 Programming Manual</TITLE>
+ <META CONTENT="Revision 6" NAME="DocNumber">
+ <TITLE>FLTK 1.1.6 Programming Manual</TITLE>
</HEAD>
<BODY>
<H1 ALIGN="RIGHT"><A NAME="preface">Preface</A></H1>
<P>This manual describes the Fast Light Tool Kit (&quot;FLTK&quot;)
-version 1.1.5, a C++ Graphical User Interface
+version 1.1.6, a C++ Graphical User Interface
(&quot;GUI&quot;) toolkit for UNIX, Microsoft Windows and MacOS. Each
of the chapters in this manual is designed as a tutorial for
using FLTK, while the appendices provide a convenient reference
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 $".
//
diff --git a/src/Fl_Widget.cxx b/src/Fl_Widget.cxx
index 528ac5b81..ecf9fce33 100644
--- a/src/Fl_Widget.cxx
+++ b/src/Fl_Widget.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Widget.cxx,v 1.5.2.4.2.24 2004/08/25 00:20:25 matthiaswm Exp $"
+// "$Id: Fl_Widget.cxx,v 1.5.2.4.2.25 2004/11/23 19:47:52 easysw Exp $"
//
// Base widget class for the Fast Light Tool Kit (FLTK).
//
@@ -129,6 +129,7 @@ extern void fl_throw_focus(Fl_Widget*); // in Fl_x.cxx
// However, it is only legal to destroy a "root" such as an Fl_Window,
// and automatic destructors may be called.
Fl_Widget::~Fl_Widget() {
+ if (flags() & COPIED_LABEL) free(label_.value);
parent_ = 0; // Don't throw focus to a parent widget.
fl_throw_focus(this);
}
@@ -244,6 +245,27 @@ int Fl_Widget::contains(const Fl_Widget *o) const {
return 0;
}
+
+void
+Fl_Widget::label(const char *a) {
+ if (flags() & COPIED_LABEL) {
+ free(label_.value);
+ clear_flag(COPIED_LABEL);
+ }
+ label_.value=a;
+ redraw_label();
+}
+
+
+void
+Fl_Widget::copy_label(const char *a) {
+ if (flags() & COPIED_LABEL) free(label_.value);
+ set_flag(COPIED_LABEL);
+ label_.value=strdup(a);
+ redraw_label();
+}
+
+
//
-// End of "$Id: Fl_Widget.cxx,v 1.5.2.4.2.24 2004/08/25 00:20:25 matthiaswm Exp $".
+// End of "$Id: Fl_Widget.cxx,v 1.5.2.4.2.25 2004/11/23 19:47:52 easysw Exp $".
//