DO NOT REPLY TO THIS MESSAGE. INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.
[STR New]
Link: http://www.fltk.org/str.php?L2754
Version: 1.3-feature
Option to automatically copy labels so dynamic and local/stack variables
can be used without worrying about scope.
Link: http://www.fltk.org/str.php?L2754
Version: 1.3-feature
Index: FL/Fl.H
===================================================================
--- FL/Fl.H (revision 9157)
+++ FL/Fl.H (working copy)
@@ -176,6 +176,9 @@
/// tooltip text will open a little tooltip window until the mouse leaves
/// the widget. If disabled, no tooltip is shown.
OPTION_SHOW_TOOLTIPS,
+ /// Make a copy of the labels provided to Fl_Widget instead of
+ /// using the pointer passed to it.
+ OPTION_COPY_LABELS,
// don't change this, leave it always as the last element
/// For internal use only.
OPTION_LAST
@@ -878,6 +881,10 @@
/** Sets the functions to call to draw and measure a specific labeltype. */
static void set_labeltype(Fl_Labeltype, Fl_Labeltype from); // is it defined
?
+ // labels:
+ static void copy_labels(int v) { option(OPTION_COPY_LABELS, (v!=0)); };
+ static int copy_labels() { return option(OPTION_COPY_LABELS); };
+
// boxtypes:
static Fl_Box_Draw_F *get_boxtype(Fl_Boxtype);
static void set_boxtype(Fl_Boxtype, Fl_Box_Draw_F*,uchar,uchar,uchar,uchar);
Index: src/Fl_Widget.cxx
===================================================================
--- src/Fl_Widget.cxx (revision 9157)
+++ src/Fl_Widget.cxx (working copy)
@@ -126,6 +126,13 @@
parent_ = 0;
if (Fl_Group::current()) Fl_Group::current()->add(this);
+
+ // handle application option
+ if (L && Fl::copy_labels()) {
+ if ((label_.value=strdup(L))!=NULL) {
+ set_flag(COPIED_LABEL);
+ }
+ }
}
void Fl_Widget::resize(int X, int Y, int W, int H) {
@@ -289,6 +296,13 @@
void
Fl_Widget::label(const char *a) {
+
+ // handle application option
+ if (Fl::copy_labels()) {
+ copy_label(a);
+ return;
+ }
+
if (flags() & COPIED_LABEL) {
// reassigning a copied label remains the same copied label
if (label_.value == a)
@@ -303,10 +317,14 @@
void
Fl_Widget::copy_label(const char *a) {
- if (flags() & COPIED_LABEL) free((void *)(label_.value));
- if (a) {
+ if (a==label_.value) {
+ return;
+ }
+ if (flags() & COPIED_LABEL) {
+ free((void *)(label_.value));
+ }
+ if (a && (label_.value=strdup(a))!=NULL) {
set_flag(COPIED_LABEL);
- label_.value=strdup(a);
} else {
clear_flag(COPIED_LABEL);
label_.value=(char *)0;
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev