// This is how the utilty class has been implemented
// Interface required in WinForm
public interface IGetCurrEditor
{
WPDynamic.WPDLLInt CurrEdit();
}
// Utility class WPAMenuItem
public class WPAMenuItem : System.Windows.Forms.MenuItem
{
// the ID
public int wpaID = -1;
// the for to work with (must have CurrEdit function)
private IGetCurrEditor ParentForm;
// Constructor
public WPAMenuItem(IGetCurrEditor p, string wpa)
{
ParentForm = p;
if(ParentForm.CurrEdit()!=null)
{
wpaID = ParentForm.CurrEdit().wpaGetID(wpa);
if (wpaID<0) Enabled = false;
Text = wpa;
}
}
// Process a click
protected override void OnClick(EventArgs e)
{
if ((wpaID>=0)&&(ParentForm.CurrEdit()!=null))
ParentForm.CurrEdit().wpaExec(wpaID,"");
}
// Update the string of this item
public void Update()
{
string n="",c="",h="";
if ((wpaID>=0)&&(ParentForm.CurrEdit()!=null))
{
if (ParentForm.CurrEdit().Memo.wpaGetCaption(
wpaID, ref n, ref c, ref h))
{
Text = c;
}
}
for(int i=0;i<MenuItems.Count;i++)
if (MenuItems[i] is WPAMenuItem)
(MenuItems[i] as WPAMenuItem).Update();
}
// Update the current state
protected override void OnPopup(EventArgs e)
{
if (ParentForm.CurrEdit()!=null)
{
byte[] flags = ParentForm.CurrEdit().wpaGetFlags(0);
if (wpaID>=0)
{
Enabled = (flags[wpaID]&1)!=0;
Checked = (flags[wpaID]&2)!=0;
}
for(int i=0;i<MenuItems.Count;i++)
if (MenuItems[i] is WPAMenuItem)
{
if ((MenuItems[i] as WPAMenuItem).wpaID>=0)
{
MenuItems[i].Enabled =
(flags[(MenuItems[i] as WPAMenuItem).wpaID]&1)!=0;
MenuItems[i]. Checked =
(flags[(MenuItems[i] as WPAMenuItem).wpaID]&2)!=0;
}
}
}
}
}