Add Localized Menu Items

[Top]  [Chapter]  [Previous]  [Next]

 

The GUI definition file of TextDynamic contains the localization of the dialog strings and also action captions and hints. Some action names have been reserved to store the caption for menu drop downs only.

 

This enum definition can be used for code which creates a menu in code:

 

[Flags]

internal enum wpaMenuCaps

{

 wpaDropDownMenuFile=1,

 wpaDropDownMenuEdit=2,

 wpaDropDownMenuView=4,

 wpaDropDownMenuInsert=8,

 wpaDropDownMenuFormat=16,

 wpaDropDownMenuExtras=32,

 wpaDropDownMenuData=64,

 wpaDropDownMenuTable=128,

 wpaDropDownMenuWindow=256,

 wpaDropDownMenuInfo=512

}

 

Using this action names and a selection of the 'intelligent' actions you can create a framwork to create the menu of your form "on the fly".

 

We created a menu class which handles the update of the strings completely automatically.

 

You only need to to implement the IGetCurrEditor interface in your winform.

 

public class WinForm : System.Windows.Forms.Form,IGetCurrEditor

{  

  public WPDynamic.WPDLLInt CurrEdit()  { return wpdllInt1; }

    ....

}

 

Now you can create the procedure which creates the menu. The actions for each menu drop down are provided as string array. This makes this code easy to be updated (green lines).

 

private void UpdateMenu(System.Windows.Forms.MainMenu menu, wpaMenuCaps selection)

{

 // Select the items for the menus - implemented as array of string array

 string[][] wpaMenuItems = new string[10][];

 // DropDownMenuFile

 wpaMenuItems[0]= new string[]

 {"DiaOpen","DiaSave","-","DiaPagePropEx","DiaPreview","DiaPrint"};

 // DropDownMenuEdit

 wpaMenuItems[1]= new string[]

 {"undo","redo","-","DiaFind","DiaReplace","-","copy","paste","SelAll"};

 // DropDownMenuView

 wpaMenuItems[2]= new string[]

 {"DiaManageHeaderFooter","ShowCR","-", "LayoutNormal",

                         "zoom100", "zoomwidth", "zoomfullpage", "zoomdoublepage" };

 // DropDownMenuInsert

 wpaMenuItems[3]= new string[]

 {"DiaINSGRAPHIC", "DiaINSSymbol", "DiaINSHyperlink", "DiaINSFields"};

 // DropDownMenuFormat

 wpaMenuItems[4]= new string[]

 {"DiaParagraphProp", "DiaParagraphBorder", "DiaBulletOutlines"};

 // DropDownMenuExtra

 wpaMenuItems[5]= new string[]

 {"DiaSpellcheck", "DiaSpellOptions", "SpellAsYouGo"};

 // DropDownMenuData

 wpaMenuItems[6]= new string[]

 {/*TODO*/};

 // DropDownMenuTable

 wpaMenuItems[7]= new string[]

 {"DiaINSTable", "DiaParagraphBorder",

         "InsColBefore","InsCol", "InsRowBefore", "InsRow"};

 // DropDownMenuWindow

 wpaMenuItems[8]= new string[]

 {/*TODO*/};

 // DropDownMenuInfo

 wpaMenuItems[9]= new string[]

 {"DiaWPAbout","DiaWPDebug"};

 // ----------------------------------------------------------------

 string[] wpaMenuCapsNames = {

                                 "DropDownMenuFile","DropDownMenuEdit",

                                 "DropDownMenuView","DropDownMenuInsert",

                                 "DropDownMenuFormat","DropDownMenuExtras",

                                 "DropDownMenuData", "DropDownMenuTable",

                                 "DropDownMenuWindow", "DropDownMenuInfo"};

 WPDynamic.WPAMenuItem item, pitem;

 for(int m=0, a=1; m<=10;m++,a=a*2)

 {

                         if(((int)selection&a)==a)

                         {

                            pitem = new WPDynamic.WPAMenuItem(

                                 this, wpaMenuCapsNames[m]);

                            // Now create the menu items

                            foreach(String s in wpaMenuItems[m])

                            {

                                   item = new WPDynamic.WPAMenuItem(this,s);

                                   pitem.MenuItems.Add(item);

                            }

                            pitem.Update();

                            menu.MenuItems.Add(pitem);

                         }

 }

}

 

After adding to event Form.Load -

 

 // Initialize MainMenu

 mainMenu1.MenuItems.Clear(); // Start from scratch!

 UpdateMenu(mainMenu1,

 wpaMenuCaps.wpaDropDownMenuFile|

 wpaMenuCaps.wpaDropDownMenuEdit|

 wpaMenuCaps.wpaDropDownMenuView|

 wpaMenuCaps.wpaDropDownMenuInsert|

 wpaMenuCaps.wpaDropDownMenuFormat|

 wpaMenuCaps.wpaDropDownMenuExtras|

//        wpaMenuCaps.wpaDropDownMenuData|

 wpaMenuCaps.wpaDropDownMenuTable|

//        wpaMenuCaps.wpaDropDownMenuWindow|

 wpaMenuCaps.wpaDropDownMenuInfo );

 

 

this is how the menu will look at runtime.

 

clip0094

 

 

 

 


[addlocalizedmenuitems.htm]    Copyright © 2007 by WPCubed GmbH