Index: Fl_Type.cxx
===================================================================
--- Fl_Type.cxx	(revision 8095)
+++ Fl_Type.cxx	(working copy)
@@ -466,6 +466,7 @@
   selected = new_selected = 0;
   visible = 0;
   name_ = 0;
+  dirty_name_ = 0;
   label_ = 0;
   user_data_ = 0;
   user_data_type_ = 0;
@@ -622,6 +623,10 @@
   }
 }
 
+void Fl_Type::dirty_name(const char *n) {
+  storestring(n,dirty_name_);
+}
+
 void Fl_Type::label(const char *n) {
   if (storestring(n,label_,1)) {
     setlabel(label_);
@@ -658,6 +663,13 @@
   if (next) next->prev = prev; else last = prev;
   if (current == this) current = 0;
   if (parent) parent->remove_child(this);
+  if (name_) free((void*)name_);
+  if (dirty_name_) free((void*)dirty_name_);
+  if (label_) free((void*)label_);
+  if (callback_) free((void*)callback_);
+  if (user_data_) free((void*)user_data_);
+  if (user_data_type_) free((void*)user_data_type_);
+  if (comment_) free((void*)comment_);
 }
 
 int Fl_Type::is_parent() const {return 0;}
@@ -871,6 +883,11 @@
     write_word("comment");
     write_word(comment());
   }
+  if (dirty_name()) {
+    write_indent(level+1);
+    write_word("dirty_name");
+    write_word(dirty_name());
+  }
   if (is_parent() && open_) write_word("open");
   if (selected) write_word("selected");
 }
@@ -886,6 +903,8 @@
     callback(read_word());
   else if (!strcmp(c,"comment"))
     comment(read_word());
+  else if (!strcmp(c,"dirty_name"))
+    dirty_name(read_word());
   else if (!strcmp(c,"open"))
     open_ = 1;
   else if (!strcmp(c,"selected"))
Index: Fl_Type.h
===================================================================
--- Fl_Type.h	(revision 8095)
+++ Fl_Type.h	(working copy)
@@ -54,6 +54,7 @@
   Fl_Type();
 
   const char *name_;
+  const char *dirty_name_;
   const char *label_;
   const char *callback_;
   const char *user_data_;
@@ -97,6 +98,8 @@
 
   const char *name() const {return name_;}
   void name(const char *);
+  const char *dirty_name() const {return dirty_name_;}
+  void dirty_name(const char *);
   const char *label() const {return label_;}
   void label(const char *);
   const char *callback() const {return callback_;}
Index: Fl_Widget_Type.cxx
===================================================================
--- Fl_Widget_Type.cxx	(revision 8095)
+++ Fl_Widget_Type.cxx	(working copy)
@@ -45,6 +45,78 @@
 // instance, sets the widget pointers, and makes all the display
 // update correctly...
 
+char * replace(
+    char const * const original,
+    char const * const pattern,
+    char const * const replacement
+) {
+  size_t const replen = strlen(replacement);
+  size_t const patlen = strlen(pattern);
+  size_t const orilen = strlen(original);
+
+  size_t patcnt = 0;
+  const char * oriptr;
+  const char * patloc;
+
+  // find how many times the pattern occurs in the original string
+  for (oriptr = original; (patloc = strstr(oriptr, pattern)); oriptr = patloc + patlen)
+  {
+    patcnt++;
+  }
+
+  {
+    // allocate memory for the new string
+    size_t const retlen = orilen + patcnt * (replen - patlen);
+    char * const returned = (char *) malloc( sizeof(char) * (retlen + 1) );
+
+    if (returned != NULL)
+    {
+      // copy the original string,
+      // replacing all the instances of the pattern
+      char * retptr = returned;
+      for (oriptr = original; (patloc = strstr(oriptr, pattern)); oriptr = patloc + patlen)
+      {
+        size_t const skplen = patloc - oriptr;
+        // copy the section until the occurence of the pattern
+        strncpy(retptr, oriptr, skplen);
+        retptr += skplen;
+        // copy the replacement
+        strncpy(retptr, replacement, replen);
+        retptr += replen;
+      }
+      // copy the rest of the string.
+      strcpy(retptr, oriptr);
+    }
+    return returned;
+  }
+}
+
 extern int reading_file;
 int force_parent;
 extern int gridx;
@@ -314,7 +386,10 @@
       snprintf(buf, sizeof(buf), "Widget Properties (%d widgets)", numselected);
       o->hide();
     } else {
-      o->static_value(current_widget->name());
+      o->static_value(
+			current_widget->dirty_name() ?
+			current_widget->dirty_name() :
+			current_widget->name());
       o->show();
       snprintf(buf, sizeof(buf), "%s Properties", current_widget->title());
     }
@@ -322,7 +397,12 @@
     the_panel->label(buf);
   } else {
     if (numselected == 1) {
-      current_widget->name(o->value());
+      const char *aname = o->value();
+      current_widget->dirty_name(aname);
+      char *aname_clean = replace(aname[0] == '@' ?
+                    (aname[1] == '&' ? (aname+2) : (aname+1)) : aname, "@", "_");
+      current_widget->name(aname_clean);
+      free(aname_clean);
       // I don't update window title, as it probably is being closed
       // and wm2 (a window manager) barfs if you retitle and then
       // hide a window:
@@ -2068,10 +2148,19 @@
 
 extern int varused_test, varused;
 
+#define CHECK_NO_NEW() \
+  const char *dn = dirty_name();\
+  bool no_new = (dn && dn[0] == '@');\
+  bool is_pointer = !(no_new && dn[1] == '&');\
+  const char *arrow_or_dot = is_pointer ? "->" : ".";
+
 void Fl_Widget_Type::write_code1() {
   const char* t = subclassname(this);
   const char *c = array_name(this);
-  if (c) {
+  CHECK_NO_NEW();
+  if(no_new){
+      write_h("  //%s *%s;\n", t, name());
+  } else if (c) {
     if (class_name(1)) {
       write_public(public_);
       write_h("  %s *%s;\n", t, c);
@@ -2126,21 +2215,31 @@
       }
   }
 
+  c = name();
   write_c("%s{ ", indent());
   if (varused) write_c("%s* o = ", t);
-  if (name()) write_c("%s = ", name());
+  if (c) write_c(no_new ? (varused ? (is_pointer ? "%s;\n" : "&%s;\n") : "\n") :
+                      "%s = ", c);
+  if(no_new){
+     write_c("%s  Fl_Group::current()->add(%s);\n", indent(), c);
+     write_c("%s  %s%sresize", indent(), c, arrow_or_dot);
+  } else {
+      write_c("new %s", t);
+  }
   if (is_window()) {
     // Handle special case where user is faking a Fl_Group type as a window,
     // there is no 2-argument constructor in that case:
-    if (!strstr(t, "Window"))
-      write_c("new %s(0, 0, %d, %d", t, o->w(), o->h());
-    else
-      write_c("new %s(%d, %d", t, o->w(), o->h());
+    if (!strstr(t, "Window")){
+      write_c("(0, 0, %d, %d", int(o->w()), int(o->h()));
+    } else {
+      write_c("(%d, %d", int(o->w()), int(o->h()));
+    }
   } else {
-    write_c("new %s(%d, %d, %d, %d", t, o->x(), o->y(), o->w(), o->h());
+    write_c("(%d, %d, %d, %d", int(o->x()), int(o->y()), int(o->w()), int(o->h()));
   }
   if (label() && *label()) {
-    write_c(", ");
+    if(no_new) write_c(");\n%s  %s%slabel(", indent(), c, arrow_or_dot);
+    else write_c(", ");
     switch (i18n_type) {
     case 0 : /* None */
         write_cstring(label());
@@ -2198,10 +2297,11 @@
   case FL_WHITE:		color_name = "FL_WHITE";		break;
   }
   const char *var = is_class() ? "this" : name() ? name() : "o";
+  CHECK_NO_NEW();
   if (color_name) {
-    write_c("%s%s->%s(%s);\n", indent(), var, field, color_name);
+    write_c("%s%s%s%s(%s);\n", indent(), var, arrow_or_dot, field, color_name);
   } else {
-    write_c("%s%s->%s((Fl_Color)%d);\n", indent(), var, field, color);
+    write_c("%s%s%s%s((Fl_Color)%d);\n", indent(), var, arrow_or_dot, field, color);
   }
 }
 
@@ -2209,9 +2309,10 @@
 void Fl_Widget_Type::write_widget_code() {
   Fl_Widget* tplate = ((Fl_Widget_Type*)factory)->o;
   const char *var = is_class() ? "this" : name() ? name() : "o";
+  CHECK_NO_NEW();
 
   if (tooltip() && *tooltip()) {
-    write_c("%s%s->tooltip(",indent(), var);
+    write_c("%s%s%stooltip(",indent(), var, arrow_or_dot);
     switch (i18n_type) {
     case 0 : /* None */
         write_cstring(tooltip());
@@ -2232,11 +2333,11 @@
   }
 
   if (is_spinner() && ((Fl_Spinner*)o)->type() != ((Fl_Spinner*)tplate)->type())
-    write_c("%s%s->type(%d);\n", indent(), var, ((Fl_Spinner*)o)->type());
+    write_c("%s%s%stype(%d);\n", indent(), var, arrow_or_dot, ((Fl_Spinner*)o)->type());
   else if (o->type() != tplate->type() && !is_window())
-    write_c("%s%s->type(%d);\n", indent(), var, o->type());
+    write_c("%s%s%stype(%d);\n", indent(), var, arrow_or_dot, o->type());
   if (o->box() != tplate->box() || subclass())
-    write_c("%s%s->box(FL_%s);\n", indent(), var, boxname(o->box()));
+    write_c("%s%s%sbox(FL_%s);\n", indent(), var, arrow_or_dot, boxname(o->box()));
 
   // write shortcut command if needed
   int shortcut = 0;
@@ -2246,25 +2347,26 @@
   else if (is_text_display()) shortcut = ((Fl_Text_Display*)o)->shortcut();
   if (shortcut) {
     if (use_FL_COMMAND && (shortcut & (FL_CTRL|FL_META))) {
-      write_c("%s%s->shortcut(FL_COMMAND|0x%x);\n", indent(), var, shortcut & ~(FL_CTRL|FL_META));
+      write_c("%s%s%sshortcut(FL_COMMAND|0x%x);\n", indent(), var, arrow_or_dot,
+              shortcut & ~(FL_CTRL|FL_META));
     } else {
-      write_c("%s%s->shortcut(0x%x);\n", indent(), var, shortcut);
+      write_c("%s%s%sshortcut(0x%x);\n", indent(), var, arrow_or_dot, shortcut);
     }
   }
 
   if (is_button()) {
     Fl_Button* b = (Fl_Button*)o;
-    if (b->down_box()) write_c("%s%s->down_box(FL_%s);\n", indent(), var,
-			       boxname(b->down_box()));
-    if (b->value()) write_c("%s%s->value(1);\n", indent(), var);
+    if (b->down_box()) write_c("%s%s%sdown_box(FL_%s);\n", indent(), var,
+			       arrow_or_dot, boxname(b->down_box()));
+    if (b->value()) write_c("%s%s%svalue(1);\n", indent(), var, arrow_or_dot);
   } else if (!strcmp(type_name(), "Fl_Input_Choice")) {
     Fl_Input_Choice* b = (Fl_Input_Choice*)o;
-    if (b->down_box()) write_c("%s%s->down_box(FL_%s);\n", indent(), var,
-			       boxname(b->down_box()));
+    if (b->down_box()) write_c("%s%s%sdown_box(FL_%s);\n", indent(), var,
+			       arrow_or_dot, boxname(b->down_box()));
   } else if (is_menu_button()) {
     Fl_Menu_* b = (Fl_Menu_*)o;
-    if (b->down_box()) write_c("%s%s->down_box(FL_%s);\n", indent(), var,
-			       boxname(b->down_box()));
+    if (b->down_box()) write_c("%s%s%sdown_box(FL_%s);\n", indent(), var,
+			       arrow_or_dot, boxname(b->down_box()));
   }
   if (o->color() != tplate->color() || subclass())
     write_color("color", o->color());
@@ -2273,69 +2375,69 @@
   if (image) image->write_code(var);
   if (inactive) inactive->write_code(var, 1);
   if (o->labeltype() != tplate->labeltype() || subclass())
-    write_c("%s%s->labeltype(FL_%s);\n", indent(), var,
-	    item_name(labeltypemenu, o->labeltype()));
+    write_c("%s%s%slabeltype(FL_%s);\n", indent(), var,
+	    arrow_or_dot, item_name(labeltypemenu, o->labeltype()));
   if (o->labelfont() != tplate->labelfont() || subclass())
-    write_c("%s%s->labelfont(%d);\n", indent(), var, o->labelfont());
+    write_c("%s%s%slabelfont(%d);\n", indent(), var, arrow_or_dot, o->labelfont());
   if (o->labelsize() != tplate->labelsize() || subclass())
-    write_c("%s%s->labelsize(%d);\n", indent(), var, o->labelsize());
+    write_c("%s%s%slabelsize(%d);\n", indent(), var, arrow_or_dot, o->labelsize());
   if (o->labelcolor() != tplate->labelcolor() || subclass())
     write_color("labelcolor", o->labelcolor());
   if (is_valuator()) {
     Fl_Valuator* v = (Fl_Valuator*)o;
     Fl_Valuator* f = (Fl_Valuator*)(tplate);
     if (v->minimum()!=f->minimum())
-      write_c("%s%s->minimum(%g);\n", indent(), var, v->minimum());
+      write_c("%s%s%sminimum(%g);\n", indent(), var, arrow_or_dot, v->minimum());
     if (v->maximum()!=f->maximum())
-      write_c("%s%s->maximum(%g);\n", indent(), var, v->maximum());
+      write_c("%s%s%smaximum(%g);\n", indent(), var, arrow_or_dot, v->maximum());
     if (v->step()!=f->step())
-      write_c("%s%s->step(%g);\n", indent(), var, v->step());
+      write_c("%s%s%sstep(%g);\n", indent(), var, arrow_or_dot, v->step());
     if (v->value()) {
       if (is_valuator()==3) { // Fl_Scrollbar::value(double) is nott available
-        write_c("%s%s->Fl_Slider::value(%g);\n", indent(), var, v->value());
+        write_c("%s%s%sFl_Slider::value(%g);\n", indent(), var, arrow_or_dot, v->value());
       } else {
-        write_c("%s%s->value(%g);\n", indent(), var, v->value());
+        write_c("%s%s%svalue(%g);\n", indent(), var, arrow_or_dot, v->value());
       }
     }
     if (is_valuator()>=2) {
       double x = ((Fl_Slider*)v)->slider_size();
       double y = ((Fl_Slider*)f)->slider_size();
-      if (x != y) write_c("%s%s->slider_size(%g);\n", indent(), var, x);
+      if (x != y) write_c("%s%s%sslider_size(%g);\n", indent(), var, arrow_or_dot, x);
     }
   }
   if (is_spinner()) {
     Fl_Spinner* v = (Fl_Spinner*)o;
     Fl_Spinner* f = (Fl_Spinner*)(tplate);
     if (v->minimum()!=f->minimum())
-      write_c("%s%s->minimum(%g);\n", indent(), var, v->minimum());
+      write_c("%s%s%sminimum(%g);\n", indent(), var, arrow_or_dot, v->minimum());
     if (v->maximum()!=f->maximum())
-      write_c("%s%s->maximum(%g);\n", indent(), var, v->maximum());
+      write_c("%s%s%smaximum(%g);\n", indent(), var, arrow_or_dot, v->maximum());
     if (v->step()!=f->step())
-      write_c("%s%s->step(%g);\n", indent(), var, v->step());
+      write_c("%s%s%sstep(%g);\n", indent(), var, arrow_or_dot, v->step());
     if (v->value()!=1.0f)
-      write_c("%s%s->value(%g);\n", indent(), var, v->value());
+      write_c("%s%s%svalue(%g);\n", indent(), var, arrow_or_dot, v->value());
   }
 
   {Fl_Font ff; int fs; Fl_Color fc; if (textstuff(4,ff,fs,fc)) {
     Fl_Font f; int s; Fl_Color c; textstuff(0,f,s,c);
-    if (f != ff) write_c("%s%s->textfont(%d);\n", indent(), var, f);
-    if (s != fs) write_c("%s%s->textsize(%d);\n", indent(), var, s);
+    if (f != ff) write_c("%s%s%stextfont(%d);\n", indent(), var, arrow_or_dot, f);
+    if (s != fs) write_c("%s%s%stextsize(%d);\n", indent(), var, arrow_or_dot, s);
     if (c != fc) write_color("textcolor", c);
   }}
   const char* ud = user_data();
   if (class_name(1) && !parent->is_widget()) ud = "this";
   if (callback()) {
-    write_c("%s%s->callback((Fl_Callback*)%s", indent(), var, callback_name());
+    write_c("%s%s%scallback((Fl_Callback*)%s", indent(), var, arrow_or_dot, callback_name());
     if (ud)
       write_c(", (void*)(%s));\n", ud);
     else
       write_c(");\n");
   } else if (ud) {
-    write_c("%s%s->user_data((void*)(%s));\n", indent(), var, ud);
+    write_c("%s%s%suser_data((void*)(%s));\n", indent(), var, arrow_or_dot, ud);
   }
   if (o->align() != tplate->align() || subclass()) {
     int i = o->align();
-    write_c("%s%s->align(Fl_Align(%s", indent(), var,
+    write_c("%s%s%salign(Fl_Align(%s", indent(), var, arrow_or_dot,
 	    item_name(alignmenu, i & ~FL_ALIGN_INSIDE));
     if (i & FL_ALIGN_INSIDE) write_c("|FL_ALIGN_INSIDE");
     write_c("));\n");
@@ -2347,28 +2449,49 @@
   if (ww==FL_WHEN_NOT_CHANGED)
     ww = FL_WHEN_NEVER;
   if (ww != tplate->when() || subclass())
-    write_c("%s%s->when(%s);\n", indent(), var,
+    write_c("%s%s%swhen(%s);\n", indent(), var, arrow_or_dot,
             item_name(whensymbolmenu, ww));
   if (!o->visible() && o->parent())
-    write_c("%s%s->hide();\n", indent(), var);
+    write_c("%s%s%shide();\n", indent(), var, arrow_or_dot);
   if (!o->active())
-    write_c("%s%s->deactivate();\n", indent(), var);
+    write_c("%s%s%sdeactivate();\n", indent(), var, arrow_or_dot);
   if (!is_group() && resizable())
     write_c("%sFl_Group::current()->resizable(%s);\n", indent(), var);
   if (hotspot()) {
     if (is_class())
       write_c("%shotspot(%s);\n", indent(), var);
     else if (is_window())
-      write_c("%s%s->hotspot(%s);\n", indent(), var, var);
+      write_c("%s%s%shotspot(%s);\n", indent(), var, arrow_or_dot, var);
     else
-      write_c("%s%s->window()->hotspot(%s);\n", indent(), var, var);
+      write_c("%s%s%swindow()->hotspot(%s);\n", indent(), var, arrow_or_dot, var);
   }
 }
 
 void Fl_Widget_Type::write_extra_code() {
-  for (int n=0; n < NUM_EXTRA_CODE; n++)
-    if (extra_code(n) && !isdeclare(extra_code(n)))
-      write_c("%s%s\n", indent(), extra_code(n));
+  for (int n=0; n < NUM_EXTRA_CODE; n++){
+    char *pc, *ec = (char*)extra_code(n);
+    if (ec && !isdeclare(ec)){
+      if(ec[0] == '='){ //do macro substitutions
+          pc = ++ec; //skip "=" 
+          const char *nm = name() ? nm : "o";
+          const char *nk = subclassname(this);
+		  const char *nd = dirty_name();
+          if(name()){
+            if(nd){
+              pc = ec = replace(ec, "$(dirty_name)", nd);
+            } else pc = 0;
+            ec = replace(ec, "$(name)", nm);
+            if(pc) free(pc);
+            pc = ec;
+          }
+          if(nk) pc = replace(ec, "$(class)", nk);
+          write_c("%s%s\n", indent(), pc);
+          if(nm) free(ec);
+          if(nk) free(pc);
+      }
+      else write_c("%s%s\n", indent(), ec);
+    }
+  }
 }
 
 void Fl_Widget_Type::write_block_close() {
