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

[STR New]

Link: http://www.fltk.org/str.php?L2597
Version: 1.4-feature


Hi, Manolo. I'm sorry for the late answer.

1) This is simple test FL file

# data file for the Fltk User Interface Designer (fluid)
version 1.0300 
i18n_type 1 
i18n_include <libintl.h> 
i18n_function gettext 
header_name {.h} 
code_name {.cxx}
Function {make_window()} {open
} {
  Fl_Window {} {open
    xywh {288 362 412 286} type Double visible
  } {
    Fl_Menu_Bar {} {open selected
      xywh {0 0 565 20}
    } {
      Submenu {} {
        label 1 open
        xywh {0 0 61 19}
      } {
        MenuItem {} {
          label A
          xywh {0 0 29 19}
        }
        MenuItem {} {
          label B
          xywh {0 0 29 19}
        }
        Submenu {} {
          label 2 open
          xywh {0 0 61 19}
        } {
          MenuItem {} {
            label C
            xywh {0 0 29 19}
          }
        }
      }
      Submenu {} {
        label 3 open
        xywh {0 0 61 19}
      } {
        MenuItem {} {
          label D
          xywh {0 0 29 19}
        }
        MenuItem {} {
          label E
          xywh {0 0 29 19}
        }
      }
      Submenu {} {
        label 4 open
        xywh {0 0 61 19}
      } {
        MenuItem {} {
          label F
          xywh {0 0 30 20}
        }
      }
    }
  }
} 

Old version of FLUID prints such text:

#include <libintl.h>
#include "test_menu.h"

unsigned char menu__i18n_done = 0;
Fl_Menu_Item menu_[] = {
 {"1", 0,  0, 0, 64, FL_NORMAL_LABEL, 0, 14, 0},
 {"A", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"B", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"2", 0,  0, 0, 64, FL_NORMAL_LABEL, 0, 14, 0},
 {"C", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0},
 {0,0,0,0,0,0,0,0,0},
 {"3", 0,  0, 0, 64, FL_NORMAL_LABEL, 0, 14, 0},
 {"D", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"E", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0},
 {"4", 0,  0, 0, 64, FL_NORMAL_LABEL, 0, 14, 0},
 {"F", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0},
 {0,0,0,0,0,0,0,0,0}
};

Fl_Double_Window* make_window() {
  Fl_Double_Window* w;
  { Fl_Double_Window* o = new Fl_Double_Window(412, 286);
    w = o;
    { Fl_Menu_Bar* o = new Fl_Menu_Bar(0, 0, 565, 20);
      if (!menu__i18n_done) {
        int i=0;
        for ( ; i<10; i++) /* 10 is wrong limit of iterations! */ 
          if (menu_[i].label())
            menu_[i].label(gettext(menu_[i].label()));
        menu__i18n_done = 1;
      }
      o->menu(menu_);
    } // Fl_Menu_Bar* o
    o->end();
  } // Fl_Double_Window* o
  return w;
}

My patch calculates the correct number of items - 13

2) That patch has one more bug :( Some cases will be handled incorrectly.
New version of the patch is:

--- a\Fl_Menu_Type.cxx 2011-05-09 00:00:00.0 +0400
+++ b\Fl_Menu_Type.cxx 2011-05-09 00:00:00.0 +0400
@@ -466,7 +466,10 @@ void Fl_Menu_Type::write_code2() {
       const char *mName = mi->menu_name(i);
       for (Fl_Type* q = next; q && q->is_menu_item(); q = q->next) {
         if (((Fl_Menu_Item_Type*)q)->label()) nLabel++;
-        nItem++;
+        int thislevel = q->level; if (q->is_parent()) thislevel++;
+        int nextlevel =
+            (q->next && q->next->is_menu_item()) ? q->next->level :
next->level+1;
+        nItem += 1 + ((thislevel > nextlevel) ? (thislevel-nextlevel) :
0);
       }
       if (nLabel) {
         write_c("%sif (!%s_i18n_done) {\n", indent(), mName);


Link: http://www.fltk.org/str.php?L2597
Version: 1.4-feature

_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to