DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2707
Version: 1.3-feature


While working on the patch for STR #2706 I decided to look into some more
fluid issues that have been bugging me for a while. Here is #1:

I found many times that in Fluid designed user interfaces it is convenient
to use Fl_Group derived component classes for groups of controls repeated
many times. A Fluid generated widget class based on Fl_Group is very handy
for such uses -- except that for C++ scoping issues (access to privates,
inside class can be made not accessible for users, etc..) it would be
convenient to declare these nested in the main class. There are two ways
to implement such nested classes in Fluid, here I illustrate these with
equivalent C++ code.

Method 1 (in Fluid build "inner" class within the "outer" class):

class outer /* the main user interface panel */ {
  class inner : public Fl_Group {
    // full declaration of class here ...
  };
  ...
};

Method 2 (in Fluid build both classes at the top level):

class outer {
  class inner;   // Just a single declaration in Fluid here...
  ...
};

class outer::inner : public Fl_Group {
  ...
};

After some experimentation I found that Method 1 is a non-starter.
Generated code is wrong in way too many places, and there are even editing
bugs in Fluid making widget selections and movements "bleed" across editing
windows. Method 2 almost works. The only problem in the generated code is
the naming of the class constructors. They look like this:
"outer::inner::outer::inner()" -- both in the header and c++ files. 

I attached a patch that fixes this issue. Also attached a sample fluid
file that demonstrates a simple but plausible usage scenario. Does not
compile when translated with the original fluid, compiles after fluid is
patched.


Link: http://www.fltk.org/str.php?L2707
Version: 1.3-feature
diff -ur fltk-1.3.x-r8914-orig//fluid/Fl_Window_Type.cxx 
fltk-1.3.x-r8914//fluid/Fl_Window_Type.cxx
--- fltk-1.3.x-r8914-orig//fluid/Fl_Window_Type.cxx     2011-07-18 
23:49:30.000000000 -0500
+++ fltk-1.3.x-r8914//fluid/Fl_Window_Type.cxx  2011-08-26 17:40:07.000000000 
-0500
@@ -1476,6 +1476,15 @@
   }
 }
 
+// Convert A::B::C::D to D (i.e. keep only innermost name)
+static const char *trimclassname(const char *n) {
+  const char *nn;
+  while((nn = strstr(n, "::"))) {
+    n = nn + 2;
+  }
+  return(n);
+}
+
 void Fl_Widget_Class_Type::write_code1() {
 #if 0
   Fl_Widget_Type::write_code1();
@@ -1489,43 +1498,43 @@
 
   write_h("\nclass %s : public %s {\n", name(), c);
   if (strstr(c, "Window")) {
-    write_h("  void _%s();\n", name());
+    write_h("  void _%s();\n", trimclassname(name()));
     write_h("public:\n");
-    write_h("  %s(int X, int Y, int W, int H, const char *L = 0);\n", name());
-    write_h("  %s(int W, int H, const char *L = 0);\n", name());
-    write_h("  %s();\n", name());
+    write_h("  %s(int X, int Y, int W, int H, const char *L = 0);\n", 
trimclassname(name()));
+    write_h("  %s(int W, int H, const char *L = 0);\n", trimclassname(name()));
+    write_h("  %s();\n", trimclassname(name()));
 
     // a constructor with all four dimensions plus label
-    write_c("%s::%s(int X, int Y, int W, int H, const char *L)\n", name(), 
name());
+    write_c("%s::%s(int X, int Y, int W, int H, const char *L)\n", name(), 
trimclassname(name()));
     write_c("  : %s(X, Y, W, H, L) {\n", c);
-    write_c("  _%s();\n", name());
+    write_c("  _%s();\n", trimclassname(name()));
     write_c("}\n\n");
 
     // a constructor with just the size and label. The window manager will 
position the window
-    write_c("%s::%s(int W, int H, const char *L)\n", name(), name());
+    write_c("%s::%s(int W, int H, const char *L)\n", name(), 
trimclassname(name()));
     write_c("  : %s(0, 0, W, H, L) {\n", c);
     write_c("  clear_flag(16);\n");
-    write_c("  _%s();\n", name());
+    write_c("  _%s();\n", trimclassname(name()));
     write_c("}\n\n");
     
     // a constructor that takes size and label from the Fluid database
-    write_c("%s::%s()\n", name(), name());
+    write_c("%s::%s()\n", name(), trimclassname(name()));
     write_c("  : %s(0, 0, %d, %d, ", c, o->w(), o->h());
     const char *cstr = label();
     if (cstr) write_cstring(cstr);
     else write_c("0");
     write_c(") {\n");
     write_c("  clear_flag(16);\n");
-    write_c("  _%s();\n", name());
+    write_c("  _%s();\n", trimclassname(name()));
     write_c("}\n\n");
     
-    write_c("void %s::_%s() {\n", name(), name());
+    write_c("void %s::_%s() {\n", name(), trimclassname(name()));
 //    write_c("  %s *w = this;\n", name());
   } else {
     write_h("public:\n");
-    write_h("  %s(int X, int Y, int W, int H, const char *L = 0);\n", name());
+    write_h("  %s(int X, int Y, int W, int H, const char *L = 0);\n", 
trimclassname(name()));
 
-    write_c("%s::%s(int X, int Y, int W, int H, const char *L)\n", name(), 
name());
+    write_c("%s::%s(int X, int Y, int W, int H, const char *L)\n", name(), 
trimclassname(name()));
     if (wc_relative)
       write_c("  : %s(0, 0, W, H, L) {\n", c);
     else
_______________________________________________
fltk-dev mailing list
fltk-dev@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to