Building a NewMenu with localized texts gives me errors

5 posts / 0 new
Last post
walkero
walkero's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 2009-05-03 16:54
Building a NewMenu with localized texts gives me errors

Hello guys,
I am pretty confused while I try to build a new menu for iGame. The reason I am doing it is that on AROS 68K there is a problem with the old menu and doesn't show up at all.

To compile iGame for 68K I am using NDK39 and MUI 3.8 SDK. So, started build the new menu like below

  1. static struct NewMenu MenuMainWin[] =
  2. {
  3. { NM_TITLE, "Actions" , 0 ,0 ,0 ,(APTR)MEN_ACTIONS },
  4. { NM_ITEM , "Scan repositories..." ,"R",0 ,0 ,(APTR)MEN_SCAN },
  5. { NM_ITEM , "Add game..." ,"A",0 ,0 ,(APTR)MEN_ADDGAME },
  6. { NM_ITEM , NM_BARLABEL , 0 ,0 ,0 ,(APTR)0 },
  7. { NM_ITEM , "About..." ,"?",0 ,0 ,(APTR)MEN_ABOUT },
  8. { NM_ITEM , NM_BARLABEL , 0 ,0 ,0 ,(APTR)0 },
  9. { NM_ITEM , "Quit" ,"Q",0 ,0 ,(APTR)MEN_QUIT },
  10.  
  11. { NM_END,NULL,0,0,0,NULL }
  12. };

The above works fine and the menu shows up on AROS 68K, along with other OSes. But when I try to replace a label with something like

  1. GetMBString(MSG_MNlabel2Actions)

but I get an error like

error 46: initializer not a constant

Below is the GetMBString() which returns a const unsigned char *

  1. const unsigned char* GetMBString(const unsigned char* ref)
  2. {
  3. if (ref[1] == '\0')
  4. return &ref[2];
  5. return ref;
  6. }

Below you can see how the MSG_MNlabel2Actions is defined in code that is generated by flexcat, using the .cd file.

  1. extern struct FC_String iGame_Strings[104];
  2.  
  3. #define MSG_MNlabel2Actions (iGame_Strings[3].msg)
  4. #define _MSG_MNlabel2Actions (iGame_Strings+3)

Below is how the iGame_Strings struct is configured.

  1. struct FC_String iGame_Strings[104] = {
  2. { (STRPTR) "A front-end to WHDLoad", 0 },
  3. { (STRPTR) "Emmanuel Vasilakis", 1 },
  4. { (STRPTR) "iGame", 2 },
  5. { (STRPTR) "Actions", 3 }
  6. };

I also changed the whole locale file to use CatComp exported strings and GetCatalogStr(), but the error is again the same.

Can you please help me on solving this one, because it drives me crazy a few days now. What am I doing wrong?

jabirulo
jabirulo's picture
Offline
Last seen: 2 weeks 4 days ago
Joined: 2013-05-30 00:53
Re: Building a NewMenu with localized texts gives me errors

Hi, in Mixer this is how NewMenu is build (menus.c):

  1. ...
  2. #define CATCOMP_NUMBERS
  3. #define CATCOMP_BLOCK
  4. #define CATCOMP_CODE
  5. #include "mixer_strings.h"
  6. extern struct LocaleInfo li;
  7.  
  8. #define STR_ID(x) ( (STRPTR)(x) )
  9. #define MENU_ID(x) ( (APTR)(x) )
  10.  
  11. struct NewMenu MenuStripDescriptors[] = { // MUST match # in menus.h
  12. { NM_TITLE, STR_ID(-1), 0 , 0, 0, MENU_ID(0) }, // 0 = PROJECT menutitle
  13. { NM_ITEM, STR_ID(MSG_PROJECT_LOAD), "O", 0, 0, MENU_ID(MID_LOAD) }, // 1
  14. { NM_ITEM, STR_ID(MSG_PROJECT_SAVE), "S", 0, 0, MENU_ID(MID_SAVE) }, // 2
  15. { NM_ITEM, STR_ID(MSG_PROJECT_MODIFY), 0 , 0, 0, MENU_ID(MID_MODIFY) }, // 3
  16. { NM_ITEM, STR_ID(MSG_PROJECT_HIDE), "H", 0, 0, MENU_ID(MID_HIDE) }, // 4
  17. { NM_ITEM, STR_ID(MSG_PROJECT_ICONIFY), "I", 0, 0, MENU_ID(MID_ICONIFY)}, // 5
  18. { NM_ITEM, NM_BARLABEL, 0 , 0, 0, MENU_ID(0) }, // 6
  19. { NM_ITEM, STR_ID(MSG_PROJECT_ABOUT), "?", 0, 0, MENU_ID(MID_ABOUT) }, // 7
  20. { NM_ITEM, NM_BARLABEL, 0 , 0, 0, MENU_ID(0) }, // 8
  21. { NM_ITEM, STR_ID(MSG_PROJECT_QUIT), "Q", 0, 0, MENU_ID(MID_QUIT) }, // 9
  22. { NM_TITLE, STR_ID(-1), 0 , 0, 0, MENU_ID(0) }, // 10 = EDIT menutitle
  23. { NM_ITEM, STR_ID(MSG_EDIT_DEFAULTS), "D", 0, 0, MENU_ID(MID_DEFAULTS) }, // 11
  24. { NM_ITEM, STR_ID(MSG_EDIT_LASTSAVED), "L", 0, 0, MENU_ID(MID_LASTSAVED)}, // 12
  25. { NM_ITEM, STR_ID(MSG_EDIT_RESTORE), "R", 0, 0, MENU_ID(MID_RESTORE) }, // 13
  26.  
  27. { NM_END, STR_ID(-1), 0 , 0, 0, MENU_ID(0)}
  28. };
  29. ...

later on main it uses this to use translations (main.c):

  1. ...
  2. #include <proto/locale.h>
  3. #define CATCOMP_NUMBERS
  4. #define CATCOMP_BLOCK
  5. //#define CATCOMP_CODE
  6. #include "include/mixer_strings.h"
  7. struct Library *LocaleBase = NULL;
  8. struct LocaleIFace *ILocale = NULL;
  9. struct LocaleInfo li;
  10. ...
  11. TranslateMenus(&li, MenuStripDescriptors);
  12. ...
  13. void TranslateMenus(struct LocaleInfo *li, struct NewMenu *nm)
  14. {
  15. while(nm->nm_Type != NM_END)
  16. {
  17. if(nm->nm_Label != NM_BARLABEL)
  18. nm->nm_Label = (STRPTR)GetString(li, (int32)nm->nm_Label);
  19.  
  20. nm++;
  21. }
  22. }

and catalog sources are build like this:
CatComp mixer.cd CFILE include/mixer_strings.h

If your program is gouing to be only AOS4.1'aware, it could be easier to use "menuclass":

  1. ...
  2. akdt->OBJ(OID_MENUS) = NewObject(NULL, "menuclass",
  3.  
  4. MA_AddChild, NewObject(NULL, "menuclass",
  5. MA_Type,T_MENU, MA_Label,GETMSG(MSG_AKDT_MENU_PROJECT),
  6. MA_AddChild, NewObject(NULL, "menuclass",
  7. MA_Type,T_ITEM, MA_Label,GETMSG(MSG_AKDT_MENU_PROJECT_OPEN),
  8. MA_ID, AKDT_MENU_PROJECT_OPEN,
  9. MA_Key, "O",
  10. MA_Image, MenuImage("open",akdt->akdt_Screen),
  11. TAG_END),
  12. MA_AddChild, NewObject(NULL, "menuclass",
  13. MA_Type,T_ITEM, MA_Label,GETMSG(MSG_AKDT_MENU_PROJECT_SAVEAS),
  14. MA_ID, AKDT_MENU_PROJECT_SAVEAS,
  15. MA_Key, "A",
  16. MA_Image, MenuImage("saveas",akdt->akdt_Screen),
  17. TAG_END),
  18. ...

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

jabirulo
jabirulo's picture
Offline
Last seen: 2 weeks 4 days ago
Joined: 2013-05-30 00:53
Re: Building a NewMenu with localized texts gives me errors

Not sure but the problem you get is 'cos your are declaring "struct NewMenu MenuMainWin[] =" and you try to add "inside" a function, that's not possible. Don't know how to explain it better/clearer.

As you can see in example above (mixer menus.c and main.c), it declares a struct with "fixed" values (builtin strings) and later they are "replaced" with translations.

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

walkero
walkero's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 2009-05-03 16:54
Re: Building a NewMenu with localized texts gives me errors

@jabirulo
Thank you so much for your help and explanation, and for pointing me in the right direction. I got it working.

It would be so nice if this was possible to work just by giving a simple char * there.

And the Reaction MenuClass is also a very good way to create menus. That's what I am using on my ReAction based apps, but the one I am currently updating is based on MUI.

Thanks again for your help.

hypex
hypex's picture
Offline
Last seen: 3 months 2 weeks ago
Joined: 2011-09-09 16:20
Re: Building a NewMenu with localized texts gives me errors

Could it be because you declared the menu as static? With const data this will fine. But if you need to call a function then that become dynamic at run time. I think one way around it would be to declare the menu as non static. I can see how static is useful in place. But if you need to build it at run time it's not static any more. Perhaps build it once and reference as a pointer?

Log in or register to post comments