Page tree
Skip to end of metadata
Go to start of metadata

Top: VB6; Bottom: C#. 

Generated XAML in VS2013

 

WPF Xaml Authoring Code

The following is a the current gmSL scripting logic that directs the authoring for WPF Xaml files.  This script file is distributed as source with the product.  You make make a project-specific copy then modify and extend it according to your requirements.  Coming in 1Q2018: we will be releasing an .NET API and other product changes to help developers implement advanced, custom upgrades such as for WPF C# (or VB.NET) rather than gmSL.  Contact us to learn more.

int hasEvtHandler(int formRoot, int ctlRoot, string srcEvtName)
{
   int        evtRoot;
   string     eventName;
   int        eventRoot;
   tVbControl vbControl;

   if (Character.Substr(srcEvtName,0,1)== "_"  && ctlRoot > Defines.OPC_MAXIMUM) 
   {
       vbControl = Store.GetVector(ctlRoot);
       evtRoot = vbControl.nxtVector;
       if(evtRoot == 0) evtRoot = ctlRoot;
       eventName = Store.GetIdent(evtRoot) + srcEvtName;
   }
   else
   {
       eventName = srcEvtName;
   }   
   
   eventRoot = Store.FindVector(eventName,formRoot);
   if(eventRoot)
   {
      return 1;
   }
   return 0;
}
int addPropFromEvtHandler(int formRoot, int ctlRoot, string srcEvtName, string netProp, string netPropValue)
{
   int        evtRoot;
   string     eventName;
   int        eventRoot;
   tVbControl vbControl;

   if (Character.Substr(srcEvtName,0,1)== "_") 
   {
       vbControl = Store.GetVector(ctlRoot);
       evtRoot = vbControl.nxtVector;
       if(evtRoot == 0) evtRoot = ctlRoot;
       eventName = Store.GetIdent(evtRoot) + srcEvtName;
   }
   else
   {
       eventName = srcEvtName;
   }   
   
   eventRoot = Store.FindVector(eventName,formRoot);
   if(eventRoot)
   {
      Write.Text(" " + netProp + "=""");
      Write.Text(netPropValue);
      Write.Character("""");
      return 1;
   }
   return 0;
}

int addEvtHandler(int formRoot, int ctlRoot, string srcEvtName, string netEvtName)
{
   int        evtRoot;
   string     eventName;
   int        eventRoot;
   tVbControl vbControl;

   if (Character.Substr(srcEvtName,0,1)== "_" && ctlRoot > Defines.OPC_MAXIMUM) 
   {
       vbControl = Store.GetVector(ctlRoot);
       evtRoot = vbControl.nxtVector;
       if(evtRoot == 0) evtRoot = ctlRoot;
       eventName = Store.GetIdent(evtRoot) + srcEvtName;
   }
   else
   {
       eventName = srcEvtName;
   }   
   eventRoot = Store.FindVector(eventName,formRoot);
   if(eventRoot)
   {
      Write.Text(" " + netEvtName + "=""");
      Write.Text(Store.GetName(eventRoot));
      Write.Character("""");
      return 1;
   }
   return 0;
}

int wrtPropertyIfEqual(int ctlType, int iCode, string srcName, string EqualValue, string netName, string netValue)
{
    string sValue = "";
    
    sValue = getPropertyIfEqual(ctlType, iCode, srcName, EqualValue, netName, netValue);
    
    if (sValue != "")
    {
        Write.Text(sValue);
                return 1;
    }
}

string getPropertyIfEqual(int ctlType, int iCode, string srcName, string EqualValue, string netName, string netValue)
{
    string sValue = "";
    string mout = "";
    
    sValue = getStringValue(ctlType,iCode,srcName,"!");
    
    if (netName == "WindowStartupLocation")
    {
        //System.LogMessage("srcName: " + srcName + " sValue:" + sValue);
    }
    
    if (sValue == EqualValue)
    {
        mout = " " + netName + "=""" + netValue + """";
    }
    
    return mout;
}

string getPropertyIfEqualAndEqual(int ctlType, int iCode, string Prop1, string Value1, string Prop2, string Value2, string netName, string netValue)
{
    string sValue1 = "";
    string sValue2 = "";
    string mout = "";
    
    sValue1 = getStringValue(ctlType,iCode,Prop1,"!");
    sValue2 = getStringValue(ctlType,iCode,Prop2,"!");
    
    if (netName == "IsEditable")
    {
        //System.LogMessage("srcName: " + srcName + " sValue:" + sValue);
    }
    
    if (sValue1 == Value1 && sValue2 == Value2)
    {
        mout = " " + netName + "=""" + netValue + """";
    }
    
    return mout;
}

string getStringValue(int ctlType, int iCode, string srcName, string nullValue)
{
   int iProp;
   string sValue;

   if (srcName != "!") iProp = ControlData.FindProperty(ctlType,srcName,iCode);
   if(iProp)
   {
      sValue = ControlData.GetProperty(iProp);
      if (ctlType == OPC.FNT && srcName =="Size") sValue = ControlData.GetFontSize(iProp);
   }
   else
   {
        iProp = 1;                
        sValue = nullValue;
   }
   
   return sValue;
}

string getStringProperty(int ctlType, int iCode, string srcName, string netName, string defaultValue)
{
   string sValue = "";
   string mout = "";
   
   if (netName == "!") netName = srcName;
   
   sValue = getStringValue(ctlType,iCode,srcName,"!");

   if (sValue == "!" || sValue == "")
   {
       sValue = defaultValue;
   }
   
   if (sValue != "!")
   {
       mout = " " + netName + "=""" + sValue + """";
   }
   
   
   return mout;
}

int wrtIsCancelButton(int formRoot, int ctlRoot, string netName, string netValue)
{   
   int    iCode;
   int    iProp;
   int    iValue;
   string sValue;
   int    ctlType;
   int    frmRoot;
   
   
   frmRoot = Store.GetFirst(formRoot);    
   iCode = ControlData.LoadCode(frmRoot);
   ctlType = Store.GetObjectType(frmRoot);
   if(ctlType != OPC.FOR) return 0;
   
   iProp = ControlData.FindProperty(ctlType,"CancelButton",iCode);
   
   if (iProp)
   {
      //Need to get addr of CancelButton
      //If addr matches ctlRoot then autor netName = netValue, can be hard coded for this methond IsCancel = "True"
      //this needs repeated for acceptbutton
   }
   
   //System.Logmessage("iProp " + iProp + " iValue:" + iValue + " ctlRoot:" + ctlRoot);
}

int wrtTextProperty(int ctlType, int iCode, string srcName, string netName, string defaultValue)
{
   int iProp;
   string sValue;
   int opcd;
   int subc;
   tCodeBlock codptr;
   int        pcnt;


   //Optional netName
   if (netName == "!") netName = srcName;
   if (srcName != "!") iProp = ControlData.FindProperty(ctlType,srcName,iCode);
   if(iProp)
   {
      if (ctlType == OPC.FNT && srcName =="Size") sValue = ControlData.GetFontSize(iProp);
      else sValue = ControlData.GetProperty(iProp);
   }
   else
   {
        if (defaultValue != "!")
        {
            iProp = 1;                
            sValue = defaultValue;
        }    
   }
   if (iProp) 
   {
        if (Character.FindFirst(sValue,0,"FrxData") != 1)
        {
            sValue = XAMLEncode(sValue);
            Write.Text(" " + netName + "=""");
            Write.Text(sValue);
            Write.Text("""");
        }
        else
        {
            //Get code info, dig into frxinfo block
            //codptr = Opcode.GetCode();
            //pcnt = Opcode.GetLength();
            //opcd = Opcode.GetOperation(codptr,iProp,subc);
            //string temp;
            //temp = Store.GetName(subc-54);
            //Need to get the text next.  Maybe the size of an frxdata block.
            //System.LogMessage(" ip:" + iProp + "  ic: " + iCode + " opcd:" + opcd + "  subc:" + subc + " " + temp);
            //Opcode.DumpCode(iProp-10,iProp+10);
        }
   }
   return iProp;
}
int wrtStringProperty(int ctlType, int iCode, string srcName, string netName, string defaultValue)
{
   int iProp;
   string sValue;

   //Optional netName
   if (netName == "!") netName = srcName;
   if (srcName != "!") iProp = ControlData.FindProperty(ctlType,srcName,iCode);
   if(iProp)
   {
      if (ctlType == OPC.FNT && srcName =="Size") sValue = ControlData.GetFontSize(iProp);
      else sValue = ControlData.GetProperty(iProp);
   }
   else
   {
        if (defaultValue != "!")
        {
            iProp = 1;                
            sValue = defaultValue;
        }    
   }
   if (iProp) Write.Text(" " + netName + "=""" + sValue + """");
   return iProp;
}

int wrtPictureProperty(int formRoot, int ctlType, int iCode, string srcName, string netName, string defaultValue)
{
     int iProp;
     string sValue;
       
     iProp = ControlData.FindProperty(ctlType,srcName,iCode);
     if (iProp)
     {
         string picaddr = ControlData.GetProperty(iProp);

         string frmName = Symbol.ClassName(formRoot);
         sValue = "Images/" + frmName + "." + picaddr + "." + srcName + ".png";
     }
     else
     {
        if (defaultValue != "!")
        {
            iProp = 1;                
            sValue = defaultValue;
        }    
     }

     if (iProp) Write.Text(" " + netName + "=""" + sValue + """");
     return iProp;
}

string getColorProperty(int ctlType, int iCode, string srcName, string netName, string defaultValue)
{
   int iProp;
   string sValue;

   if (srcName != "!") iProp = ControlData.FindProperty(ctlType,srcName,iCode);
   if(iProp)
   {
      sValue = ControlData.GetProperty(iProp);
      sValue = getColor(sValue);
   }
   else
   {
        if (defaultValue != "!")
        {
            iProp = 1;
            sValue = defaultValue;
        }
   }
   if (iProp) 
   {
       return " " + netName + "=""" + sValue + """";
   }
   else
   {
       return "";
   }
}

int wrtColorProperty(int ctlType, int iCode, string srcName, string netName, string defaultValue)
{
    string sValue = "";
    
    sValue = getColorProperty(ctlType, iCode, srcName, netName, defaultValue);
    if (sValue != "")
    {
        Write.Text(sValue);
        return 1;
    }
    return 0;
}

int wrtIntProperty(int ctlType, int iCode, string srcName, string netName, string defaultValue, int offset)
{
   int iProp;
   int iValue;
   string sValue;

   if (srcName != "!") iProp = ControlData.FindProperty(ctlType,srcName,iCode);
   if(iProp)
   {
      iValue = ControlData.GetValue(iProp) ;
      
      iValue = iValue - offset;
      if (iValue < 0) iValue = 0;
      
      sValue = iValue;
   }
   else
   {
        if (defaultValue != "!")
        {
            iProp = 1;                
            sValue = defaultValue;
        }    
   }
   if (iProp) Write.Text(" " + netName + "=""" + sValue + """");
   return iProp;
}

string getIntProperty(int ctlType, int iCode, string srcName, string defaultValue, int offset)
{
   int iProp;
   int iValue;
   string sValue;

   if (srcName != "!") iProp = ControlData.FindProperty(ctlType,srcName,iCode);
   if(iProp)
   {
      iValue = ControlData.GetValue(iProp) ;
      if(iValue >= offset) iValue = iValue - offset;
      sValue = iValue;
   }
   else
   {
        if (defaultValue != "!")
        {
            iProp = 1;                
            sValue = defaultValue;
        }    
   }
   return sValue;
}

string getEnumProperty(int ctlType, int iCode, string srcName, string netName, string defaultValue)
{
   int iProp;
   int iValue;
   string sValue;
   int iPos;
   
   if (srcName != "!") iProp = ControlData.FindProperty(ctlType,srcName,iCode);
   if(iProp)
   {
       if (netName=="Visibility") 
       {
           sValue = "Hidden";  // only have to author Visibility=Hidden;  wpf default = vb6 default
       }
       else if (netName=="FlowDirection") 
       {
           iValue = ControlData.GetValue(iProp);
           if (iValue==1) sValue = "RightToLeft";
       }
       else
       {
           sValue = ControlData.GetProperty(iProp);
       }
   }
   else
   {
        if (defaultValue != "!")
        {
            iProp = 1;                
            sValue = defaultValue;
        }    
   }
   
   iPos = Character.FindFirst(sValue,0,".");
   if(iPos)
   {
       int lpos = iPos;
       
       while (lpos)
       {
           iPos = lpos;
           lpos = Character.FindFirst(sValue, lpos, ".");
           if (lpos == 0) break;
           lpos = iPos + lpos;
       }
       sValue = Character.Remove(sValue,0,iPos);
   }
   string mout = "";
   
   if (iProp)
   {
       mout = " " + netName + "=""" + sValue + """";
   }
   
   return mout;
}

int wrtEnumProperty(int ctlType, int iCode, string srcName, string netName, string defaultValue)
{
   int iProp;
   int iValue;
   string sValue;
   int iPos;
   
   if (srcName != "!") iProp = ControlData.FindProperty(ctlType,srcName,iCode);
   if(iProp)
   {
       if (netName=="Visibility") 
       {
           sValue = "Hidden";  // only have to author Visibility=Hidden;  wpf default = vb6 default
       }
       else if (netName=="FlowDirection") 
       {
           iValue = ControlData.GetValue(iProp);
           if (iValue==1) sValue = "RightToLeft";
       }
       else
       {
           sValue = ControlData.GetProperty(iProp);
       }
   }
   else
   {
        if (defaultValue != "!")
        {
            iProp = 1;                
            sValue = defaultValue;
        }    
   }
   
   iPos = Character.FindFirst(sValue,0,".");
   if(iPos)
   {
       int lpos = iPos;
       
       while (lpos)
       {
           iPos = lpos;
           lpos = Character.FindFirst(sValue, lpos, ".");
           if (lpos == 0) break;
           lpos = iPos + lpos;
       }
       sValue = Character.Remove(sValue,0,iPos);
   }
   
   if (iProp) Write.Text(" " + netName + "=""" + sValue + """");
   return iProp;
}

int wrtBoolProperty(int ctlType, int iCode, string srcName, string netName, string defaultValue, int TrueValue)
{
   int iProp;
   int iValue;
   string sValue;

   if (srcName != "!") iProp = ControlData.FindProperty(ctlType,srcName,iCode);
   if(iProp)
   {
       iValue = ControlData.GetValue(iProp);
       if(iValue == TrueValue) sValue = "True";       
   }
   else
   {
        if (defaultValue != "!")
        {
            iProp = 1;                
            sValue = defaultValue;
        }    
   }
   if (iProp) Write.Text(" " + netName + "=""" + sValue + """");
   return iProp;
}

int wrtTwipsProperty(int ctlType, int iCode, string srcName, string netName)
{
   int iProp;
   int iValue;

   iProp = ControlData.FindProperty(ctlType,srcName,iCode);
   if(iProp)
   {
      iValue = ControlData.GetValue(iProp)/15;
      Write.Text(" " + netName + "=""" + iValue + """");   
   }
   return iProp;
}

string getSurfaceAttribs(int formRoot)
{
   int    iCode;
   int    iProp;
   int    iValue;
   int    frmRoot;
   int    iSize;
   int    iSize2;
   string sHeight;
   string sWidth;
   string sValue;
   int    ctlType;
   
   frmRoot = Store.GetFirst(formRoot);    
   iCode = ControlData.LoadCode(frmRoot);
   ctlType = Store.GetObjectType(frmRoot);
   if(ctlType != OPC.FOR) return "";

   sValue = "";

   sValue = sValue + getColorProperty(ctlType,iCode,"BackColor", "Background", "#FFF0F0F0"); // Form
   sValue = sValue + getStringProperty(ctlType,iCode,"ScaleLeft","!","0"); // Form
   sValue = sValue + getStringProperty(ctlType,iCode,"ScaleTop","!","0"); // Form
   //sValue = sValue + getStringProperty(ctlType,iCode,"ScaleWidth","!","!"); // Form
   //sValue = sValue + getStringProperty(ctlType,iCode,"ScaleHeight","!","!"); // Form
   sValue = sValue + getEnumProperty(ctlType,iCode,"ScaleMode","ScaleMode","Pixels"); // Form
   
   return sValue;
}

string getFormAttribs(int formRoot)
{
   int    iCode;
   int    iProp;
   int    iValue;
   int    frmRoot;
   int    iSize;
   int    iSize2;
   string sHeight;
   string sWidth;
   string sValue;
   int    ctlType;
   
   frmRoot = Store.GetFirst(formRoot);    
   iCode = ControlData.LoadCode(frmRoot);
   ctlType = Store.GetObjectType(frmRoot);
   if(ctlType != OPC.FOR) return "";

   sValue = "";
   iProp = ControlData.FindProperty(ctlType,"ClientHeight",iCode);
   iSize = ControlData.GetValue(iProp);
   iProp = ControlData.FindProperty(ctlType,"ClientTop",iCode);
   iSize2 = ControlData.GetValue(iProp);   
   if(iProp)
   {
       iSize = iSize + iSize2;
       sValue =  sValue + " Height=""" + iSize + """";
   }
   iProp = ControlData.FindProperty(ctlType,"ClientWidth",iCode);
   iSize = ControlData.GetValue(iProp);
   iProp = ControlData.FindProperty(ctlType,"ClientLeft",iCode);
   iSize2 = ControlData.GetValue(iProp);   
   if(iProp)
   {
      iSize = iSize + iSize2 + 5;  // 5 assumes sizable borders; 
      sValue =  sValue + " Width=""" + iSize + """";
   }
   sValue = sValue + getStringProperty(ctlType,iCode,"Caption","Title","!"); // Form
   sValue = sValue + getPropertyIfEqual(ctlType,iCode,"BorderStyle","System.Windows.Forms.FormBorderStyle.None","WindowStyle","None"); // Form
   sValue = sValue + getPropertyIfEqual(ctlType,iCode,"ControlBox","false","ResizeMode","NoResize"); // Form
   
   if (Character.FindFirst(sValue,0,"ResizeMode") == 0 && Character.FindFirst(sValue,0,"WindowStyle") == 0)
   {
        //ToolWindow lets you resize.  If ControlBox is false, resize is disabled and ResizeMode=NoResize takes presidence
        sValue = sValue + getPropertyIfEqualAndEqual(ctlType,iCode,"MinButton","false","MaxButton","False","WindowStyle", "ToolWindow"); // Form
   }
   sValue = sValue + getPropertyIfEqual(ctlType,iCode,"ShowInTaskbar","false","ShowInTaskbar","False"); // Form
   
   //StartUpPosition
   sValue = sValue + getPropertyIfEqual(ctlType,iCode,"StartUpPosition","!","WindowStartupLocation","Manual"); // Form
   sValue = sValue + getPropertyIfEqual(ctlType,iCode,"StartUpPosition","System.Windows.Forms.FormStartPosition.CenterParent","WindowStartupLocation","CenterOwner"); // Form
   sValue = sValue + getPropertyIfEqual(ctlType,iCode,"StartUpPosition","System.Windows.Forms.FormStartPosition.CenterScreen","WindowStartupLocation","CenterScreen"); // Form
   
   
     iProp = ControlData.FindProperty(ctlType,"Icon",iCode);
     if (iProp)
     {
         string picaddr = ControlData.GetProperty(iProp);

         string frmName = Symbol.ClassName(formRoot);
         sValue = sValue + " Icon=" + """Images\" + frmName + "." + picaddr + ".Icon.ico"""; // " Format fix for notepad++
     }
   
   
   return sValue;
}

string getColor(string vb6Color)
{
	string cvalue;
	int invalid = 0;
    // convert 0x??BBGGRR to #SSRRGGBB
    
    if (vb6Color=="default") return "Grey";
	
	//System color conversions
	//VB6 system colors: http://msdn.microsoft.com/en-us/library/aa265064%28VS.60%29.aspx
	//WPF system colors: http://msdn.microsoft.com/en-us/library/system.windows.systemcolors.aspx
	//UPGRADE_TODO: need to have tool support all system colors
	
	if (vb6Color=="System.Windows.SystemColors.ScrollBarColor") return "{x:Static SystemColors.ScrollBarBrush}"; 
	if (vb6Color=="System.Windows.SystemColors.WindowColor") return "{x:Static SystemColors.WindowBrush}"; 
	if (vb6Color=="System.Windows.SystemColors.WindowTextColor") return "{x:Static SystemColors.WindowTextBrush}"; 
	if (vb6Color=="System.Windows.SystemColors.ActiveCaptionTextColor") return "{x:Static SystemColors.ActiveCaptionTextBrush}"; 
	if (vb6Color=="System.Windows.SystemColors.HighlightColor") return "{x:Static SystemColors.HighlightBrush}"; 
	
	if (vb6Color=="0x80000000") return "{x:Static SystemColors.ScrollBarBrush}"; 
	if (vb6Color=="0x80000005") return "{x:Static SystemColors.WindowBrush}"; 
	if (vb6Color=="0x80000008") return "{x:Static SystemColors.WindowTextBrush}"; 
	if (vb6Color=="0x80000009") return "{x:Static SystemColors.ActiveCaptionTextBrush}"; 
	if (vb6Color=="0x8000000D") return "{x:Static SystemColors.HighlightBrush}"; 

	//Look for S which will mean system font
	invalid = Character.FindFirst(vb6Color, 0, "S");
	
	if (invalid>0)
	{
		System.LogMessage("Invalid Color:" + vb6color);
		return "Grey";
	}    
	
    string sat = "FF"; // Character.SubStr(vb6Color,2,2);
    string blu = Character.SubStr(vb6Color,4,2);
    string grn = Character.SubStr(vb6Color,6,2);
    string red = Character.SubStr(vb6Color,8,2);
	
    cvalue = "#" + sat+red+grn+blu;
	
	return cvalue;
}

int WPFAuthorProjectAssembly(int projectRoot,int iValue)
{
   string StartupURI = "";
   if(!Project.StartupMain)
   {
      StartupUri="StartupUri=""" + Project.Exename +".xaml""";
   }

   #TextStart
   cat >(%= Project.DeployLocation %)\(%= Project.NameSpace %).xaml <<'!)(!'
   <Application x:Class="(%= Project.NameSpace %).App"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      (%=StartupUri%)
      >
   <Application.Resources>         
   </Application.Resources>
   </Application>
   !)(!
   #TextEnd
   if (Select.Dialect == Dialects.csh)
   {
      #TextStart
      cat >(%= Project.DeployLocation %)\(%= Project.NameSpace %).xaml.cs <<'!)(!'
      using System;
      using System.Collections.Generic;
      using System.Configuration;
      using System.Data;
      using System.Linq;
      using System.Windows;

      namespace (%= Project.NameSpace %)
      {
         /// <summary>
         /// Interaction logic for App.xaml
         /// </summary>
         public partial class App : Application
         {
         }
      }
      !)(!
      #TextEnd
   }
   else
   {
      #TextStart
      cat >(%= Project.DeployLocation %)\(%= Project.NameSpace %).xaml.vb <<'!)(!'
      Imports System
      Imports System.Collections.Generic
      Imports System.Configuration
      Imports System.Data
      Imports System.Linq
      Imports System.Windows

      Namespace (%= Project.NameSpace %)
         ''' <summary>
         ''' Interaction logic for App.xaml
         ''' </summary>
         Public Partial Class App : Inherits Application
         End Class
      End Namespace
      !)(!
      #TextEnd
   }
   return 1;
}

void wrtFormFinish()
{
   #TextStart
   </DockPanel>
   </Window>
   !)(!
   #TextEnd
}

int wrtCommonProperties(int ctlRoot, int ctlType, int inICode, int topOffset, int leftOffset, int level)
{   
   int    iProp;
   int    iValue;
   int    iCode;
   string sValue;
   
   iCode = inICode;
   
   Write.Text(" Name=""");
   Write.Text(Store.GetName(ctlRoot));
   Write.Character("""");
      
   wrtIntProperty(ctlType, iCode, "Left", "Canvas.Left", "!",leftOffset); // common
   wrtIntProperty(ctlType, iCode, "Top", "Canvas.Top", "!",topOffset); // common
   if(ctlType != OPC.LAB)
   {
       wrtIntProperty(ctlType, iCode, "Height", "Height", "!",0); // common
       wrtIntProperty(ctlType, iCode, "Width", "Width", "!",0); // common
   }
   
   //UPGRADE_TODO: Need to make sure that this color does not need to be default for all controls
   if(ctlType == OPC.FRA || ctlType == OPC.PBX)
   {
      wrtColorProperty(ctlType, iCode, "BackColor", "Background", "#FFF0F0F0"); // common
   }
   else if (ctlType == OPC.LAB)
   {
       sValue = getStringProperty(ctlType,iCode,"BackStyle","!"); // common
       if (Character.FindFirst(sValue,0,"Transparent") == 0) wrtColorProperty(ctlType,iCode,"BackColor", "Background", "#FFF0F0F0"); // common
   }
   else if (ctlType == OPC.CMB)
   {
       sValue = getIntProperty(ctlType,iCode,"Style","Style","!"); //common
       
       if (sValue == "1") 
       {
            wrtColorProperty(ctlType,iCode,"BackColor", "Background", "!"); // common
       }
   }
   else
   {
      wrtColorProperty(ctlType, iCode, "BackColor", "Background", "!"); // common
   }
   
   
   if(ctlType != OPC.PBX)
   {
       wrtColorProperty(ctlType, iCode, "ForeColor", "Foreground", "!"); // common
       wrtStringProperty(ctlType,iCode,"TabIndex","TabIndex","!");
   }
   //wrtEnumProperty(ctlType,iCode,"Visible","Visibility","!");
   wrtStringProperty(ctlType,iCode,"Enabled","IsEnabled","!");
   wrtStringProperty(ctlType,iCode,"ToolTipText","ToolTip","!");
   
   
   //System.LogMessage(" nm:" + Store.GetName(ctlRoot) + " " + level + " toffset:" + topOffset + " loffset:" + leftOffset);
   
   
   return iCode;
}

void wrtMenuShortcuts(int formRoot,int menuRoot)
{
   int    levels[7];
   int    ctlRoot;
   int    ctlType;
   int    iChild;
   int    iCode;
   int    iCaption;
   string caption;
   string wpfCaption;
   int    level;
   string sValue;
   int x;
   string name;
   
   string shortcuts[100];
   int    shortcutsCtls[100];
   int    shortCnt = 0;
   int    hasEve;

   level = 1
   for(ctlRoot = Store.FindFirstChild(levels,menuRoot); ctlRoot != 0; ctlRoot = Store.FindNextChild(levels))
   {
      ctlType = Store.GetObjectType(ctlRoot);
      if(ctlType != OPC.MEN) break;
      iChild = Store.GetFirst(ctlRoot);
      iCode = ControlData.LoadCode(ctlRoot);
      if(iCode)
      {
          iCaption = ControlData.FindProperty(ctlType,"Caption",iCode);
          if(iCaption)
          {
             level = levels[0];
             caption = ControlData.GetProperty(iCaption);
             if(caption != "-")
             {
                
                wpfCaption = Character.Replace(caption,"&","_");
                
                sValue = getStringValue(ctlType,iCode,"Shortcut","!","!");
                hasEve = hasEvtHandler(formRoot, ctlRoot, "_Click");
                if (sValue != "!" && hasEve)
                {
                    shortcuts[shortCnt] = sValue;
                    shortcutsCtls[shortCnt] = ctlRoot;
                    shortCnt = shortCnt + 1;
                }
             }
          }
          Opcode.SetLength(iCode);
      }
   }
    
   if (shortCnt == 0) return;
    
   #TextStart
    <Window.Resources>
   #TextEnd
   
   Write.ChangeMargin(1);
   for (x = 0;x < shortCnt;x = x + 1)
   {
        Write.Text("<RoutedUICommand x:Key=""" + Store.GetName(shortcutsCtls[x]) + "_Command"" />");
        Write.Record();
   }
   Write.ChangeMargin(-1);
        
   #TextStart
    </Window.Resources>
   #TextEnd
   
       
       
       
       
       
   #TextStart
    <Window.CommandBindings>
   #TextEnd
   
   Write.ChangeMargin(1);
   for (x = 0;x < shortCnt;x = x + 1)
   {
        name = Store.GetName(shortcutsCtls[x]);
        Write.Text("<CommandBinding Command=""{StaticResource " + name + "_Command}"" Executed=""" + name + "_Click"" />");
        Write.Record();
   }
   Write.ChangeMargin(-1);
        
   #TextStart
    </Window.CommandBindings>
   #TextEnd
   
   
   
   
   #TextStart
    <Window.InputBindings>
   #TextEnd
   
   Write.ChangeMargin(1);
   for (x = 0;x < shortCnt;x = x + 1)
   {
        name = Store.GetName(shortcutsCtls[x]);
        string gest = GetGesture(shortcuts[x]);
        Write.Text("<KeyBinding Gesture=""" + gest + """ Command=""{StaticResource " + name + "_Command}"" />");
        Write.Record();
   }
   Write.ChangeMargin(-1);
        
   #TextStart
    </Window.InputBindings>
   #TextEnd
}

string GetGesture(string shortcuts)
{
    string mout = shortcuts;
    
    mout = Character.Replace(mout, " | ","+");
    mout = Character.Replace(mout, "Keys.Control","Ctrl");
    mout = Character.Replace(mout, "Keys.Shift","Shift");
    mout = Character.Replace(mout, "Keys.Alt","Alt");
    mout = Character.Replace(mout, "Keys.","");

    return mout;
}

void wrtMenu(int formRoot,int menuRoot)
{
   int    levels[7];
   int    ctlRoot;
   int    ctlType;
   int    iChild;
   int    iCode;
   int    iCaption;
   string caption;
   string wpfCaption;
   int    level;
   string sValue;

   #TextStart
   <Menu DockPanel.Dock="Top" Name="mainMenu1" IsMainMenu="True">
   #TextEnd
   Write.ChangeMargin(1);
   level = 1
   for(ctlRoot = Store.FindFirstChild(levels,menuRoot); ctlRoot != 0; ctlRoot = Store.FindNextChild(levels))
   {
      ctlType = Store.GetObjectType(ctlRoot);
      if(ctlType != OPC.MEN) break;
      iChild = Store.GetFirst(ctlRoot);
      iCode = ControlData.LoadCode(ctlRoot);
      if(iCode)
      {
          iCaption = ControlData.FindProperty(ctlType,"Caption",iCode);
          if(iCaption)
          {
             if(levels[0] < level)
             {
                Write.ChangeMargin(-1);
                Write.Line("</MenuItem>");
             }
             level = levels[0];
             caption = ControlData.GetProperty(iCaption);
             if(caption == "-") Write.Text("<Separator/>");
             else
             {
                wpfCaption = Character.Replace(caption,"&","_");
                Write.Text("<MenuItem Header=""");
                if(wpfCaption == caption) Write.Character("_");
                Write.Text(wpfCaption);
                Write.Character("""");
                Write.Text(" Name=""");
                Write.Text(Store.GetName(ctlRoot));
                Write.Character("""");
                
                wrtBoolProperty(ctlType,iCode,"Checked","IsChecked","!", 3);
                
                addEvtHandler(formRoot, ctlRoot, "_Click", "Click"); // MenuItem
                
                sValue = getStringValue(ctlType,iCode,"Shortcut","!","!"); // MenuItem
                if (sValue != "!") 
                {
                    string gest = GetGesture(sValue);
                    Write.Text(" InputGestureText=""" + gest + """");
                }
                
                if(iChild) Write.Text(" >");
                else Write.Text(" />");
             }
             Write.Record();
             if(iChild) Write.ChangeMargin(1);
          }
          Opcode.SetLength(iCode);
      }
   }
   if(levels[0] < level)
   {
      Write.ChangeMargin(-1);
      Write.Line("</MenuItem>");
   }
   Write.ChangeMargin(-1);
   #TextStart
   </Menu>
   #TextEnd
   
   
}

void wrtCheckBox(int formRoot,int ctlRoot,int topOffset, int leftOffset)
{
   int    iCode;
   int    iProp;
   int    iValue;
   string sValue;
   int    ctlType;

   ctlType = Store.GetObjectType(ctlRoot);
   iCode = ControlData.LoadCode(ctlRoot);
   Write.Text("<CheckBox");

   wrtCommonProperties(ctlRoot, ctlType, iCode, topOffset,leftOffset);

   wrtBoolProperty(ctlType,iCode,"Value","IsChecked","False",OPC.CHV.vbChecked); // CheckBox
   wrtEnumProperty(ctlType,iCode,"Alignment","FlowDirection","!"); // CheckBox
   wrtStringProperty(ctlType,iCode,"!","Margin","0,5,0,0"); // CheckBox
   addEvtHandler(formRoot, ctlRoot, "_Click", "Click"); // checkbox
   addEvtHandler(formRoot, ctlType, "_MouseMove", "MouseMove"); // CheckBox

   Write.Text(">");
   Write.Record();
   Write.ChangeMargin(1);
   
   Write.Text("<AccessText");
   wrtStringProperty(ctlType,iCode,"!","TextWrapping","Wrap"); // CheckBox
   wrtStringProperty(ctlType,iCode,"Caption","Text","!"); // CheckBox
   wrtIntProperty(ctlType,iCode,"Width","Width","!",7); // CheckBox
   Write.Text(" />");
   Write.Record();
   Write.ChangeMargin(-1);
   
   Write.Line("</CheckBox>");
   Opcode.SetLength(iCode);
}

void wrtTextBox(int formRoot,int ctlRoot,int topOffset, int leftOffset)
{
   int    iCode;
   int    iProp;
   int    iValue;
   string sValue;
   int    ctlType;

   ctlType = Store.GetObjectType(ctlRoot);
   iCode = ControlData.LoadCode(ctlRoot);
   Write.Text("<TextBox");

   wrtCommonProperties(ctlRoot, ctlType, iCode, topOffset, leftOffset);

   addEvtHandler(formRoot, ctlRoot, "_KeyPress", "PreviewKeyDown"); // TextBox
   addEvtHandler(formRoot, ctlRoot, "_KeyDown", "KeyDown"); // TextBox
   addEvtHandler(formRoot, ctlRoot, "_Click", "MouseLeftButtonUp"); // TextBox
   addEvtHandler(formRoot, ctlRoot, "_Change", "TextChanged"); // TextBox
   addEvtHandler(formRoot, ctlRoot, "_LostFocus", "LostFocus"); // TextBox   
   // TOODO: addEvtHandler(formRoot, ctlType, "_KeyDown", "KeyDown"); // TextBox KeyDown vs KeyPress?
   
   wrtTextProperty(ctlType,iCode,"Text","Text","!"); // TextBox
   wrtStringProperty(OPC.FNT,iCode,"Name","FontFamily","!"); // TextBox
   wrtStringProperty(OPC.FNT,iCode,"Size","FontSize","!"); // TextBox
   wrtStringProperty(ctlType,iCode,"Locked","IsReadOnly","!"); // TextBox

   iProp = ControlData.FindProperty(ctlType,"MultiLine",iCode); // TextBox
   if(iProp)
   {
      iValue = ControlData.GetValue(iProp);
      if(iValue)
      {
         Write.Text(" TextWrapping=""" + "Wrap" + """");
         Write.Text(" Margin=""" + "3" + """");
         Write.Text(" Padding=""" + "0" + """");
      }
   }
   iProp = ControlData.FindProperty(ctlType,"ScrollBars",iCode);
   if(iProp)
   {
      iValue = ControlData.GetValue(iProp);
      if(iValue == OPC.SBC.vbVertical)
      {
         Write.Text(" VerticalScrollBarVisibility=""" + "Visible" + """");
      }
   }
   
   Write.Text(" />");
   Write.Record();
   Opcode.SetLength(iCode);
}

void wrtFrame(int formRoot,int ctlRoot,int topOffset, int leftOffset, int level)
{
   int    iCode;
   int    iProp;
   int    iValue;
   string sValue;
   int    ctlType;
   int    childRoot;

   ctlType = Store.GetObjectType(ctlRoot);
   iCode = ControlData.LoadCode(ctlRoot);
   Write.Text("<GroupBox");
   
   string caption;
   
   caption = getStringValue(ctlType,iCode,"Caption","!");
   
   wrtStringProperty(ctlType,iCode,"Caption","Header","!");
   wrtCommonProperties(ctlRoot, ctlType, iCode, topOffset, leftOffset,level);
   addEvtHandler(formRoot, ctlRoot, "_Click", "MouseLeftButtonUp"); // Frame
   addEvtHandler(formRoot, ctlRoot, "_MouseDown", "MouseDown"); // Frame
   addEvtHandler(formRoot, ctlRoot, "_MouseUp", "MouseUp"); // Frame
   addEvtHandler(formRoot, ctlType, "_MouseMove", "MouseMove"); // Frame

   Write.Text(">");
   Write.Record();
   Write.ChangeMargin(1);
   Write.Text("<Canvas");
   Opcode.SetLength(iCode);
   
   
   if (level < 1)
   {
      topOffset = 8; //topOffset for title bar difference in vb6
   }
   else
   {
      topOffset = 16;
   }
   
   tree(level+1, " .cap:" + caption);
   
   if (caption == "" || caption == "!") topOffset = 0;
   
   leftOffset = 7;
   int children = wrtAuthorChildControlsReversed(formRoot, ctlRoot, topOffset, leftOffset, level, "Canvas");

   Write.ChangeMargin(-1);
   Write.Line("</GroupBox>");
}

int wrtAuthorChildControlsReversed(int formRoot,int ctlRoot,int topOffset, int leftOffset, int level, string tagName)
{
   int hasChildren = 0;
   int childRoot;
   int ctlType;
   int      controls[512];
   int      conCnt;
   int      conCur;
   
   for(childRoot = Store.GetFirst(ctlRoot); childRoot != 0; childRoot = Store.GetNext(childRoot))
   {
       controls[conCnt] = childRoot;
       conCnt = conCnt + 1;
       
       if (level == 0)
       {
          ctlType = Store.GetObjectType(ctlRoot);
          
          if(ctlType <= Defines.NOBJECT_NAME) break;
       }
   }
   
   if (level == 0)
   {
        tree(0,"root");
   }
   
   tree(level," |-" + Store.GetName(ctlRoot) + " " + level + " offset:" + topOffset);
   
   level = level + 1;
   
   for (conCur = conCnt-1; conCur >= 0; conCur = conCur - 1)
   {
      if (hasChildren == 0)
      {
          Write.Text(">");
          Write.Record();
          Write.ChangeMargin(1);
          hasChildren = 1;
      }
      wpfAuthorControl(formRoot,controls[conCur],topOffset,leftOffset,level);
   }
   
   if (!hasChildren)
   {
       Write.Text(" />");
       Write.Record();
   }
   else
   {
       Write.ChangeMargin(-1);
       Write.Text("</" + tagName + ">");
       Write.Record();
   }
   
   return hasChildren;
}

void wrtOptionButton(int formRoot,int ctlRoot,int topOffset, int leftOffset)
{
   int        iCode;
   int        iProp;
   int        iValue;
   string     sValue;
   int        evtRoot;
   tVbControl vbControl;
   int        ctlType;
   int        isGraphical;

   ctlType = Store.GetObjectType(ctlRoot);
   iCode = ControlData.LoadCode(ctlRoot);
   //System.LogMessage("Dumping");
   //Opcode.DumpCode(iCode,iCode+11);
   
   //System.LogMessage("RDB: ICode:" + iCode);
   
   Write.Text("<RadioButton");
   
   isGraphical=0;
   string s = getIntProperty(ctlType,iCode,"Style","Style","!"); //OptionButton
   if (s == "1") isGraphical=1;

   wrtCommonProperties(ctlRoot, ctlType, iCode, topOffset, leftOffset); // OptionButton
   addEvtHandler(formRoot, ctlRoot, "_MouseMove", "MouseMove"); // OptionButton
   addEvtHandler(formRoot, ctlRoot, "_Click", "Click"); // OptionButton
   if (isGraphical==0) wrtStringProperty(ctlType,iCode,"Caption","Content","!"); // OptionButton
   
   //wrtStringProperty(ctlType,iCode,"ToolTipText","ToolTip","!");
   wrtStringProperty(OPC.FNT,iCode,"Name","FontFamily","Arial"); // OptionButton
   wrtStringProperty(OPC.FNT,iCode,"Size","FontSize","11"); // OptionButton
   wrtStringProperty(ctlType,iCode,"Value","IsChecked","!"); // OptionButton

   if (isGraphical)
   {
     // Graphical Radio Button
     Write.Text(">");
     Write.Record();
     
     string file = "";
     
     iProp = ControlData.FindProperty(ctlType,"Picture",iCode);
     if (iProp)
     {
         //Opcode.DumpCode(iProp, iProp + 2);
         string picaddr = ControlData.GetProperty(iProp);
         //System.LogMessage("RB:" + ctlRoot + " iProp:" + iProp + "  iCode:" + iCode + "  Addr:" + picaddr);

         Write.ChangeMargin(1);
         string frmName = Symbol.ClassName(formRoot);
         Write.Text("<Image Source=" + """Images\" + frmName + "." + picaddr + ".Picture.png""  Stretch=""None"" />"); //" notepad++ format fix
         Write.Record();
         Write.ChangeMargin(-1);
     }
     Write.Text("</RadioButton>");
     Write.Record();
   }
   else
   {
     // Normal Radio Button
     Write.Text(" />");
     Write.Record();
   }
   
   Opcode.SetLength(iCode);
}
   
void wrtCommandButton(int formRoot,int ctlRoot,int topOffset, int leftOffset)
{
   int        iCode;
   int        iProp;
   int        iValue;
   string     sValue;
   tVbControl vbControl;
   int    ctlType;

   ctlType = Store.GetObjectType(ctlRoot);
   iCode = ControlData.LoadCode(ctlRoot);
   Write.Text("<Button");
   
   wrtCommonProperties(ctlRoot, ctlType, iCode, topOffset, leftOffset); // CommandButton
   addEvtHandler(formRoot, ctlRoot, "_Click", "Click"); // CommandButton
   wrtStringProperty(ctlType,iCode,"Caption","Content","!"); // CommandButton
   wrtStringProperty(OPC.FNT,iCode,"Name","FontFamily","Arial"); // CommandButton
   wrtStringProperty(OPC.FNT,iCode,"Size","FontSize","11"); // CommandButton
   wrtIsCancelButton(formRoot, ctlRoot, "IsCancel", "True");
   //wrtPropertyIfEqual(ctlType,iCode,"Cancel", "", "IsCancel", "True"); // CommandButton

   Write.Text(" />");
   Write.Record();
   Opcode.SetLength(iCode);
}

void wrtLabel(int formRoot,int ctlRoot,int topOffset, int leftOffset)
{
   int    iCode;
   int    iProp;
   int    iValue;
   string sValue;
   int    ctlType;
   string caption;
   

   ctlType = Store.GetObjectType(ctlRoot);
   iCode = ControlData.LoadCode(ctlRoot);
   Write.Text("<Label");

   wrtCommonProperties(ctlRoot, ctlType, iCode, topOffset, leftOffset); // Label
   addEvtHandler(formRoot, ctlRoot, "_Click", "MouseLeftButtonUp"); // Label   
   // TODO: addEvtHandler(formRoot, ctlRoot, "_Change", "UNKNOWN"); // Label  
   
      
   sValue = "true";//getStringValue(ctlType,iCode,"WordWrap","!"); // Label
   if (sValue == "true")
   {
       caption = getStringValue(ctlType,iCode,"Caption","!"); // Label
   }
   else
   {
       wrtStringProperty(ctlType,iCode,"Caption","Content","!"); // Label  
   }
   
   wrtStringProperty(OPC.FNT,iCode,"Name","FontFamily","Arial"); // Label
   wrtStringProperty(OPC.FNT,iCode,"Size","FontSize","11"); // Label
   wrtStringProperty(ctlType,iCode,"!","Margin","3,0"); // Label
   wrtStringProperty(ctlType,iCode,"!","Padding","0"); // Label
   
   wrtEnumProperty(ctlType,iCode,"Alignment","HorizontalContentAlignment","!"); // Label
   
   sValue = getStringProperty(ctlType,iCode,"AutoSize","!"); // Label
   
   if (Character.FindFirst(sValue,0,"true") == 0)
   {
      wrtIntProperty(ctlType, iCode, "Height", "Height", "!",0); // Label
      wrtIntProperty(ctlType, iCode, "Width", "Width", "!",0); // Label
   }
   

   if (caption == "" || caption == "!")
   {
      Write.Text(" />");
   }
   else
   {
       Write.Text(" >");
       Write.Record();
       Write.ChangeMargin(1);
       Write.Text("<TextBlock TextWrapping=""Wrap"">" + caption + "</TextBlock>");
       Write.Record();
       Write.ChangeMargin(-1);
       Write.Text("</Label>");
   }
   Write.Record();
   Opcode.SetLength(iCode);
}

void wrtUnknown(int formRoot,int ctlRoot,int topOffset, int leftOffset, string opcName)
{
   int        iCode;
   int        ctlType;

   ctlType = Store.GetObjectType(ctlRoot);
   iCode = ControlData.LoadCode(ctlRoot);
   Write.Text("<GroupBox");
   
   wrtCommonProperties(ctlRoot, OPC.PBX, iCode, topOffset, leftOffset);
    
   Write.Text(">");
   Write.Record();
   Write.ChangeMargin(1);

   Write.Text("<Canvas><TextBlock>" + opcName + "</TextBlock></Canvas>");
   Write.Record();

   Write.ChangeMargin(-1);
   Write.Text("</GroupBox>");
   Write.Record();
   
   Opcode.SetLength(iCode);
    
}

void wrtArrayString(int iProp, string attrName, int ItemDataProp)
{
   string sValue;
   string sItemValue;
   int    iEnd;
   int    iStart;
   string entry;
   string tag;
   int    cur = 0;
   
   Write.ChangeMargin(1);
   sValue = ControlData.GetProperty(iProp);
   if (ItemDataProp)
   {
       sItemValue = ControlData.GetProperty(ItemDataProp);
       
       sItemValue = sItemValue + ",";
       
       sItemValue = Character.Replace(sItemValue,"&quot;",""); 
       // Must have a strange character at the end of the string only after the replace, messes up xaml, so append "," before the replace
   }
   iEnd = 0;
   for(iStart = -5; iStart != 0; iStart = Character.FindFirst(sValue,iEnd,"&quot;"))
   {
      iStart = iStart + iEnd + 6;
      iEnd = Character.FindFirst(sValue,iStart,"&quot;");
      if(iEnd != 0)
      {
         iEnd = iEnd + iStart;
         entry = Character.Substr(sValue,iStart-1,iEnd-iStart);
      }
      else entry = Character.Substr(sValue,iStart-1,1-iStart);
      if (ItemDataProp)
      {
          tag = Split(sItemValue,",",cur);
          if (tag != "")
          {
              tag = " Tag=""" + tag + """";
          }
          else tag = "";
      }
      Write.Line("<" + attrName + " Content=""" + entry + """" + tag + " />");
      if(iEnd == 0) break;
      iEnd = iEnd + 5;
      
      cur = cur + 1;
   }
   Write.ChangeMargin(-1);
}

void wrtComboBox(int formRoot,int ctlRoot,int topOffset, int leftOffset)
{
   int    iCode;
   int    iProp;
   int    iValue;
   int    ctlType;

   ctlType = Store.GetObjectType(ctlRoot);
   iCode = ControlData.LoadCode(ctlRoot);
   Write.Text("<ComboBox");

   wrtCommonProperties(ctlRoot, ctlType, iCode, topOffset, leftOffset);
   
   wrtStringProperty(ctlType,iCode,"Text","Text","!"); // ComboBox
   wrtPropertyIfEqual(ctlType,iCode,"Style", "!", "IsEditable", "True"); // ComboBox
   //wrtPropertyIfEqual(ctlType,iCode,"Style", "System.Windows.Forms.ComboBoxStyle.DropDownList", "IsEditable", "False"); // ComboBox
   
   addEvtHandler(formRoot, ctlRoot, "_Click", "SelectionChanged"); // ComboBox
   addEvtHandler(formRoot, ctlRoot, "_Change", "TextBoxBase.TextChanged"); // ComboBox
   addEvtHandler(formRoot, ctlRoot, "_DropDown", "DropDownOpened"); // ComboBox
   addEvtHandler(formRoot, ctlRoot, "_KeyPress", "KeyDown"); // ComboBox
   addEvtHandler(formRoot, ctlType, "_DblClick", "MouseDoubleClick"); // ComboBox
   addEvtHandler(formRoot, ctlType," _GotFocus", "GotFocus"); // ComboBox

   iValue = 3;
   //Makes all controls draw +3 left and +3 top
   //Write.Text(" Margin=""" + iValue + """");
   iProp = ControlData.FindProperty(ctlType,"List",iCode);
   if(iProp == 0)
   {
      Write.Text(" />");
      Write.Record();
   }
   else
   {
      int iData = ControlData.FindProperty(ctlType,"ItemData",iCode);
      Write.Text(">");
      Write.Record();
      wrtArrayString(iProp,"ComboBoxItem",iData);
      Write.Line("</ComboBox>");
   }   
   Opcode.SetLength(iCode);
}
void wrtListBox(int formRoot,int ctlRoot,int topOffset, int leftOffset)
{
   int    iCode;
   int    iProp;
   int    iValue;
   int    ctlType;

   ctlType = Store.GetObjectType(ctlRoot);
   iCode = ControlData.LoadCode(ctlRoot);
   Write.Text("<ListBox");

   wrtCommonProperties(ctlRoot, ctlType, iCode, topOffset, leftOffset);

   addEvtHandler(formRoot, ctlRoot, "_Change", "SelectionChanged"); // ListBox
   addEvtHandler(formRoot, ctlRoot, "_LostFocus", "LostFocus"); // ListBox
   addEvtHandler(formRoot, ctlRoot, "_Click", "MouseLeftButtonUp"); // ListBox
   addEvtHandler(formRoot, ctlRoot, "_DblClick", "MouseDoubleClick"); // ListBox
   addEvtHandler(formRoot, ctlRoot, "_Scroll", "ScrollViewer.ScrollChanged"); // ListBox

   
   //Makes all controls draw +3 left and +3 top
   //wrtStringProperty(ctlType,iCode,"!","Margin","3");
   iProp = ControlData.FindProperty(ctlType,"List",iCode);
   if(iProp == 0)
   {
      Write.Text(" />");
      Write.Record();
   }
   else
   {
      int iData = ControlData.FindProperty(ctlType,"ItemData",iCode);
      Write.Text(">");
      Write.Record();
      wrtArrayString(iProp,"ListBoxItem",iData);
      Write.Line("</ListBox>");
   }   
   Opcode.SetLength(iCode);
}
void wrtPictureBox(int formRoot,int ctlRoot,int topOffset, int leftOffset, int level)
{
   int    iCode;
   int    iProp;
   int    iValue;
   int    ctlType;
   int    childRoot;
   int    hasChildren=0;

   ctlType = Store.GetObjectType(ctlRoot);
   iCode = ControlData.LoadCode(ctlRoot);
   Write.Text("<my:GraphicsPanel");
   
   wrtCommonProperties(ctlRoot, ctlType, iCode, topOffset, leftOffset); // PictureBox
   
   wrtStringProperty(ctlType, iCode, "ScaleLeft", "!", "0"); // PictureBox
   wrtStringProperty(ctlType, iCode, "ScaleTop", "!", "0"); // PictureBox
   wrtStringProperty(ctlType, iCode, "ScaleWidth", "!", "!"); // PictureBox
   wrtStringProperty(ctlType, iCode, "ScaleHeight", "!", "!"); // PictureBox
   wrtEnumProperty(ctlType, iCode, "ScaleMode", "ScaleMode", "!"); // PictureBox
   wrtPictureProperty(formRoot, ctlType, iCode, "Picture", "Picture", "!"); // PictureBox
   
   addEvtHandler(formRoot, ctlRoot, "_KeyPress", "PreviewKeyDown"); // PictureBox
   addEvtHandler(formRoot, ctlRoot, "_KeyDown", "KeyDown"); // PictureBox
   addEvtHandler(formRoot, ctlRoot, "_Click", "MouseLeftButtonUp"); // PictureBox
   addEvtHandler(formRoot, ctlRoot, "_MouseDown", "MouseDown"); // PictureBox
   addEvtHandler(formRoot, ctlRoot, "_MouseUp", "MouseUp"); // PictureBox
    // TODO: addEvtHandler(formRoot, ctlType, "_KeyDown", "KeyDown"); // PictureBox
   
   addEvtHandler(formRoot, ctlRoot, "_Resize", "SizeChanged"); // PictureBox
   addPropFromEvtHandler(formRoot, ctlRoot, "_DragDrop", "AllowDrop","True"); // PictureBox
   addEvtHandler(formRoot, ctlRoot, "_DragDrop", "Drop"); // PictureBox
   
   //Makes all controls draw +3 left and +3 top
   //wrtStringProperty(ctlType,iCode,"!","Margin","3"); // PictureBox
   
   int children = wrtAuthorChildControlsReversed(formRoot, ctlRoot, topOffset, leftOffset, level, "my:GraphicsPanel");

   Opcode.SetLength(iCode);
}
void wrtScrollBar(int formRoot,int ctlRoot,int topOffset, int leftOffset,string orientation)
{
   int    iCode;
   int    iProp;
   int    iValue;
   int    ctlType;

   ctlType = Store.GetObjectType(ctlRoot);
   iCode = ControlData.LoadCode(ctlRoot);
   Write.Text("<ScrollBar Orientation="""+ orientation + """");

   wrtCommonProperties(ctlRoot, ctlType, iCode, topOffset, leftOffset);
   
   wrtStringProperty(ctlType,iCode,"LargeChange","!","1");
   wrtStringProperty(ctlType,iCode,"SmallChange","!","1");
   wrtStringProperty(ctlType,iCode,"Min","Minimum","0");
   wrtStringProperty(ctlType,iCode,"Max","Maximum","32767");
   
   addEvtHandler(formRoot, ctlRoot, "_Change", "ScrollViewer.ScrollChanged"); // Scrollbar
   addEvtHandler(formRoot, ctlType, "_GotFocus", "GotFocus"); // HScrollBar
   addEvtHandler(formRoot, ctlType, "_Scroll", "Scroll"); // HScrollBar (same as Change?)
   
   
   //Makes all controls draw +3 left and +3 top
   //wrtStringProperty(ctlType,iCode,"!","Margin","3");

   Write.Text(" />");
   Write.Record();
   Opcode.SetLength(iCode);
}
void wrtLine(int formRoot,int ctlRoot,int topOffset, int leftOffset)
{
   int    iCode;
   int    iProp;
   int    iValue;
   int    ctlType;

   ctlType = Store.GetObjectType(ctlRoot);
   iCode = ControlData.LoadCode(ctlRoot);
   Write.Text("<Line ");
   Write.Text(" Name=""");
   Write.Text(Store.GetName(ctlRoot));
   Write.Character("""");
   
   wrtTwipsProperty(ctlType,iCode,"X1","X1");
   wrtTwipsProperty(ctlType,iCode,"X2","X2");
   wrtTwipsProperty(ctlType,iCode,"Y1","Y1");
   wrtTwipsProperty(ctlType,iCode,"Y2","Y2");

   Write.Text(" />");
   Write.Record();
   Opcode.SetLength(iCode);
}

string lvlSpace(int level)
{
   string spc = " ";
   int x;
   for (x = 0;x < level;x=x+1)
   {
       spc = spc + "   ";
   }
   return spc;
}

void wpfAuthorControl(int formRoot,int ctlRoot,int topOffset,int leftOffset,int level)
{
   int      ctlType;
   string   ctlTypeName;
   tMigInfo ctlInfo;

   ctlType = Store.GetObjectType(ctlRoot);
   
   if(ctlType == OPC.MEN) return;
   ctlInfo = Store.GetVector(ctlRoot);
   
   if(ctlInfo.Collection) return;
   
   //ctlTypeName = Symbol.FullName(ctlRoot,0);
   //dbg("   ctl:" + formRoot + ":" + ctlRoot + ":" + ctlTypeName);

   string spc = lvlSpace(level);
   tree(level," |-" + Store.GetName(ctlRoot) + " : to:" + topOffset + "  lo:" + leftOffset);
   
   if(ctlType == OPC.CBX)
   {
      wrtCheckBox(formRoot,ctlRoot,topOffset,leftOffset);
   }
   else if(ctlType == OPC.TXB)
   {
      wrtTextBox(formRoot,ctlRoot,topOffset,leftOffset);
   }
   else if(ctlType == OPC.FRA)
   {
      wrtFrame(formRoot,ctlRoot,topOffset,leftOffset,level);
   }
   else if(ctlType == OPC.OBU)
   {
      wrtOptionButton(formRoot,ctlRoot,topOffset,leftOffset);
   }
   else if(ctlType == OPC.CMB)
   {
      wrtCommandButton(formRoot,ctlRoot,topOffset,leftOffset);
   }
   else if(ctlType == OPC.LAB)
   {
      wrtLabel(formRoot,ctlRoot,topOffset,leftOffset);
   }
   else if(ctlType == OPC.PBX)
   {
      wrtPictureBox(formRoot,ctlRoot,topOffset,leftOffset);
   }
   else if(ctlType == OPC.CBO)
   {
      wrtComboBox(formRoot,ctlRoot,topOffset,leftOffset);
   }
   else if(ctlType == OPC.LSB)
   {
      wrtListBox(formRoot,ctlRoot,topOffset,leftOffset);
   }
   else if(ctlType == OPC.HBR)
   {
      wrtScrollBar(formRoot,ctlRoot,topOffset,leftOffset,"Horizontal");
   }
   else if(ctlType == OPC.VBR)
   {
      wrtScrollBar(formRoot,ctlRoot,topOffset,leftOffset,"Vertical");
   }
   else if(ctlType == OPC.TIM)
   {
       ctlTypeName = Symbol.FullName(ctlRoot,0);
       wrtUnknown(formRoot,ctlRoot,topOffset,leftOffset,"TIM");
       System.LogMessage("WPFSubsystem unknown control; TIM: " +  ctlTypeName);
   }
   else if(ctlType == OPC.MDI)
   {
       ctlTypeName = Symbol.FullName(ctlRoot,0);
       wrtUnknown(formRoot,ctlRoot,topOffset,leftOffset,"MDI");
       System.LogMessage("WPFSubsystem unknown control; MDI: " +  ctlTypeName);
   }
   else if(ctlType == OPC.SHA)
   {
       ctlTypeName = Symbol.FullName(ctlRoot,0);
       wrtUnknown(formRoot,ctlRoot,topOffset,leftOffset,"SHA");
       System.LogMessage("WPFSubsystem unknown control; SHA: " +  ctlTypeName);
   }
   else if(ctlType == OPC.LIN)
   {
       wrtLine(formRoot,ctlRoot,topOffset,leftOffset);
   }
   else if(ctlType == OPC.IMA)
   {
       ctlTypeName = Symbol.FullName(ctlRoot,0);
       wrtUnknown(formRoot,ctlRoot,topOffset,leftOffset,"IMA");
   }
   else if(ctlType == OPC.USC)
   {
       ctlTypeName = Symbol.FullName(ctlRoot,0);
       wrtUnknown(formRoot,ctlRoot,topOffset,leftOffset,"USC");
   }
   else if(ctlType == OPC.FOR)
   {
   }
   else if(ctlType > Defines.OPC_MAXIMUM)
   {
      ctlTypeName = Store.GetName(ctlType);
      if(Runtime.CallHandler(ctlType,EventType.AuthorSubsystem,ctlRoot,topOffset,leftOffset) == 0)
      {
         ctlInfo = Store.DeltaVector(ctlRoot);
         ctlInfo.PropertyBag = True;
         string msg = "WPFSubsystem: unknown control:" + ctlTypeName + ": " + Symbol.FullName(ctlRoot,0);
         System.LogMessage(msg);
         Write.Text("<!-- " + msg + " -->");
         Write.Record();
      }
   }
}

int FindMenu(int formRoot)
{
   int      ctlRoot;
   int      frmRoot;
   int      ctlType;
   
   frmRoot = Store.GetFirst(formRoot);
   for(ctlRoot = Store.GetFirst(frmRoot); ctlRoot != 0; ctlRoot = Store.GetNext(ctlRoot))
   {
      ctlType = Store.GetObjectType(ctlRoot);
      if(ctlType <= Defines.NOBJECT_NAME) break;
      if(ctlType == OPC.MEN)
      {
         return ctlRoot;
      }
   }
   return 0;
}

int WPFAuthorControls(int formRoot,int optValue)
{
   int      ctlRoot;
   int      frmRoot;
   int      ctlType;
   int      topOffset;
   tMigInfo ctlInfo;
   string   sValue;
   int      iValue;
   int      iCode;
   int      oldIndent;
   int      mnuRoot;
   
   Write.SetIndentation(4,0);
   
   frmRoot = Store.GetFirst(formRoot);
   sValue = getFormAttribs(formRoot);
   #TextStart
   cat >(%= Project.DeployLocation %)\(%= Symbol.ClassName(formRoot) %).xaml <<'!)(!'
   #TextEnd
   Write.Text("<Window" + sValue);
  
   addEvtHandler(formRoot, ctlRoot, "Form_Load", "Loaded"); // Form
   //addEvtHandler(formRoot, ctlRoot, "Form_Activate", "Activated"); // Form 
   addEvtHandler(formRoot, ctlRoot, "Form_Deactivate", "Deactivated"); // Form
   addEvtHandler(formRoot, ctlRoot, "Form_QueryUnload", "Closing"); // Form
   addEvtHandler(formRoot, ctlType, "Form_GotFocus", "GotFocus"); // Form
   addEvtHandler(formRoot, ctlType, "Form_KeyPress", "KeyDown"); // Form
   Write.Record();
   Write.ChangeMargin(1);
   #TextStart
      xmlns:my="clr-namespace:MigrationSupport.WPF;assembly=MigrationSupport.WPF"  x:Class="(%= Project.NameSpace %).(%= Symbol.ClassName(formRoot) %)"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
   #TextEnd
   
   Write.ChangeMargin(-1);

   mnuRoot = FindMenu(formRoot);
   if (mnuRoot) wrtMenuShortcuts(formRoot, mnuRoot);
   Write.Text("<DockPanel LastChildFill=""True"">");
   Write.Record();
   topOffset = 0;
   if (mnuRoot)
   {
        wrtMenu(formRoot, mnuRoot);
        topOffset = 24;
   }
   sValue = getSurfaceAttribs(formRoot);
   Write.Text("<my:GraphicsPanel Name=""Surface"" Margin=""0""" + sValue);
   addEvtHandler(formRoot, ctlRoot, "Form_Resize", "SizeChanged"); // Form

   int children = wrtAuthorChildControlsReversed(formRoot, frmRoot, topOffset, 0, 0, "my:GraphicsPanel");
   
   wrtFormFinish();
   
   wrtControlCodeBegin(formRoot);
   return 1;
}

void wrtControlCodeBegin(int formRoot)
{
   string     FormName;
   int        frmRoot;
   int        ctlRoot;
   int        ctlType;
   tVbControl ctlInfo;
   tVbControl ctlArray;
   int        levels[19];
   tCodeBlock codptr;
   int        pcnt;
   int        iProp;
   int        iCode;

   FormName = Symbol.ClassName(formRoot);
   frmRoot = Store.GetFirst(formRoot);
   codptr = Opcode.GetCode();
   pcnt = Opcode.GetLength();
   #TextStart
   cat >(%= Project.DeployLocation %)\(%= FormName %).xaml.(%= Symbol.NamedEntryLabel("LangExt",Select.Dialect) %) <<'!)(!'
   #TextEnd
   if (Select.Dialect==Dialects.csh)
   {
      #TextStart
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Windows;
      using System.Windows.Controls;
      using System.Windows.Data;
      using System.Windows.Documents;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Windows.Media.Imaging;
      using System.Windows.Navigation;
      using System.Windows.Shapes;
      using System.Windows.Forms;
      using MigrationSupport.WPF;
      using System.Runtime.InteropServices;

      namespace (%= Select.RootSpace %)(%= Project.NameSpace %)
      {
      #TextEnd
   }
   else
   {
      #TextStart
      Imports System
      Imports System.Collections.Generic
      Imports System.Linq
      Imports System.Text
      Imports System.Windows
      Imports System.Windows.Controls
      Imports System.Windows.Data
      Imports System.Windows.Documents
      Imports System.Windows.Input
      Imports System.Windows.Media
      Imports System.Windows.Media.Imaging
      Imports System.Windows.Navigation
      Imports System.Windows.Shapes
      Imports System.Windows.Forms
      Imports MigrationSupport.WPF
      Imports System.Runtime.InteropServices

      Namespace (%= Select.RootSpace %)(%= Project.NameSpace %)
      #TextEnd
   }
   Write.ChangeMargin(1);
   if (Select.Dialect==Dialects.csh)
   {
      #TextStart
      public partial class (%= FormName %) : Window
      {
      #TextEnd
   }
   else
   {
      #TextStart
      Public Partial Class (%= FormName %) : Inherits Window
      #TextEnd
   }
   Write.ChangeMargin(1);
   for(ctlRoot = Store.FindFirstChild(levels,frmRoot); ctlRoot != 0; ctlRoot = Store.FindNextChild(levels))
   {
      ctlType = Store.GetObjectType(ctlRoot);
      if(ctlType <= Defines.NOBJECT_NAME) break;
      ctlInfo = Store.GetVector(ctlRoot);
      if(ctlInfo.PropertyBag)
      {
         if (Select.Dialect==Dialects.csh) 
         {
            Write.Text("public " + Symbol.FullName(ctlType,1) + " " + Store.GetName(ctlRoot) + " = null;");
         }
         else 
         {
            Write.Text("Public " + Store.GetName(ctlRoot)) + " As " + Symbol.FullName(ctlType,1) + " = Nothing";
         }
         Write.Record();
         continue;
      }
      if(!ctlInfo.Collection) continue;
      if(ctlInfo.NeedsInit || ctlInfo.Referenced)
      {
         if (Select.Dialect==Dialects.csh)
         {
            Write.Text("public System.Collections.Generic.SortedList<int, ");
            Opcode.SetOperation(codptr,pcnt,OPC.TYP,ctlType);
            Runtime.AuthorCode(pcnt,pcnt+sizeof(OPC.TYP));
            Write.Text("> " + Store.GetName(ctlRoot) + " = null;");
         }
         else
         {
            Write.Text("Public " + Store.GetName(ctlRoot) + " As System.Collections.Generic.SortedList(Of Integer, ");
            Opcode.SetOperation(codptr,pcnt,OPC.TYP,ctlType);
            Runtime.AuthorCode(pcnt,pcnt+sizeof(OPC.TYP));
            Write.Text(") = Nothing");
         }
         Write.Record();
         
      }
   } 
    if(Project.DefInstance)
    {
        if (Select.Dialect == Dialects.csh)
        {
           #TextStart
           private static (%= FormName %) m_vb6FormDefInstance = null;
           public static (%= FormName %) DefInstance
           {
              get
              {
                  if(m_vb6FormDefInstance == null)
                  {
                      m_vb6FormDefInstance = new (%= FormName %)();
                  }
                  return m_vb6FormDefInstance;
              }
              set
              {
                  m_vb6FormDefInstance = value;
              }
           }
           #TextEnd
        }
        else 
        {
            #TextStart
            Private Shared m_vb6FormDefInstance As (%= FormName %)
            Public Shared Property DefInstance() As (%= FormName %)
               Get
                  If m_vb6FormDefInstance Is Nothing Then
                     m_vb6FormDefInstance = New (%= FormName %)()
                  End If
                  DefInstance = m_vb6FormDefInstance
               End Get
               Set(ByVal value As (%= FormName %))
                  m_vb6FormDefInstance = Value
               End Set
            End Property
            #TextEnd
        }
    }
   if (Select.Dialect == Dialects.csh)
   {
      #TextStart
      public (%= FormName %)()
      {
      #TextEnd
   }
   else
   {
      #TextStart
      <System.Diagnostics.DebuggerNonUserCode()> 
      Public Sub New()
      MyBase.New()
      #TextEnd
   }

   Write.ChangeMargin(1);
   if(Project.DefInstance)
   {
      
      if (Select.Dialect == Dialects.csh)
      {
         #TextStart
         if(m_vb6FormDefInstance == null)
         {
            m_vb6FormDefInstance = this;
         }
         #TextEnd 
      }
      else
      {
         #TextStart
         If (m_vb6FormDefInstance Is Nothing) Then
            m_vb6FormDefInstance = this;
         End If
         #TextEnd
      
      }
   }
   if (Select.Dialect==Dialects.csh)
   {
      #TextStart
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();
      //
      // TODO: Add any constructor code after InitializeComponent call
      //
      #TextEnd
   }
   else
   {
      #TextStart
      '
      ' Required for Windows Form Designer support
      '
      InitializeComponent()
      '
      ' TODO: Add any constructor code after InitializeComponent call
      '
      #TextEnd
   }
   for(ctlRoot = Store.FindFirstChild(levels,frmRoot); ctlRoot != 0; ctlRoot = Store.FindNextChild(levels))
   {
      ctlType = Store.GetObjectType(ctlRoot);
      if(ctlType <= Defines.NOBJECT_NAME) break;
      ctlInfo = Store.GetVector(ctlRoot);
      if(ctlInfo.Collection)
      {
         if(ctlInfo.NeedsInit || ctlInfo.Referenced)
         {
            
            Write.Text(Store.GetName(ctlRoot));
            if (Select.Dialect == Dialects.csh)
            {
               Write.Text(" = new System.Collections.Generic.SortedList<int, ");
               Opcode.SetOperation(codptr,pcnt,OPC.TYP,ctlType);
               Runtime.AuthorCode(pcnt,pcnt+sizeof(OPC.TYP));
               Write.Text(">();");
            }
            else
            {
               Write.Text(" = New System.Collections.Generic.SortedList(Of Integer, ");
               Opcode.SetOperation(codptr,pcnt,OPC.TYP,ctlType);
               Runtime.AuthorCode(pcnt,pcnt+sizeof(OPC.TYP));
               Write.Text(")()");
            }
            Write.Record();
         }
      }
      else if(ctlInfo.nxtVector)
      {
         ctlArray = Store.GetVector(ctlInfo.nxtVector);
         if(ctlArray.NeedsInit || ctlArray.Referenced)
         {
            Write.Text(Store.GetName(ctlInfo.nxtVector));
            Write.Text(".Add(");
            Write.Integer(ctlInfo.iVector,0);
            Write.Text(", ");
            Write.Text(Store.GetName(ctlRoot));
            if Write.Text(")");
            if (Select.Dialect == Dialects.csh) Write.Text(";");
            Write.Record();
         }
      }
      
      iCode = ControlData.LoadCode(ctlRoot);
      iProp = ControlData.FindProperty(ctlType,"Visible",iCode);
      if (iProp)
      {
          Write.Text(Store.GetName(ctlRoot));
          
          if(ctlType != OPC.MEN)
          {
              Write.Text(".Visibility = System.Windows.Visibility.Hidden");
              if (Select.Dialect == Dialects.csh) Write.Text(";");
          }
          else
          {
              Write.Text(".Visibility = System.Windows.Visibility.Collapsed");
              if (Select.Dialect == Dialects.csh) Write.Text(";");
          }
          Write.Record();
      }
   } 
   
   /*
   int hasEvt;
   hasEvt = hasEvtHandler(formRoot, frmRoot, "Form_Load");
   if (hasEvt)
   {
      Write.Text("this.Loaded += new System.Windows.RoutedEventHandler(Form_Load);");
      Write.Record();
   }
   hasEvt = hasEvtHandler(formRoot, frmRoot, "Form_Activate");
   if (hasEvt)
   {
      Write.Text("this.Activated += new EventHandler(Form_Activate);");
      Write.Record();
   }
   */
   
   Write.ChangeMargin(-1);
   if (Select.Dialect == Dialects.csh) Write.Line("}");
   else Write.Line("End Sub");
   
}

int WPFCodeScan(int subRoot,int projectRoot)
{
   int        delta;
   tCodeBlock codptr;
   int        nCode;
   tCodeBlock setTextTop;
   tCodeBlock ifOBUvalue;
   int        getOBUToolTip;
   int        nOper;
   int        icode;
   int        lcode;
   int        oldUnit;
   int        opcd;
   int        subc;
   tInfoFile  projInfo;
   int        nArg;
   int        qeAddr[10];
   int        qeType[10];
   int        lastNew;
   int        iqe;

   delta = 0;
   codptr = Opcode.GetCode();
   nCode = Opcode.GetLength();
   setTextTop = CodePattern.Read("TXB.Top,MEM.Child,STR.AssignValue",nOper);
   ifOBUvalue = CodePattern.Read("OBU.Value,MEM.Child,ARG.Boolean",nOper);

   oldUnit = Store.Unit();
   Store.Select(StorageUnit.LANG);
   getOBUToolTip = Symbol.FindIdentifier("Basic.OptionButton.ToolTipText.get");
   Store.Select(oldUnit);

   lastNew = 0;
   for(icode = 0; icode >= 0; icode = Opcode.GetNext(codptr,icode,nCode))
   {
      lcode = CodePattern.Match(icode,setTextTop);
      if(lcode)
      {
         lcode = icode + sizeof(OPC.TXB);
         nCode = Opcode.DeleteCode(lcode,nCode,sizeof(OPC.MEM));
         Opcode.SetLength(nCode);
         Opcode.SetOperation(codptr,lcode,OPC.WPO,OPC.WPO.SetCanvas);
         delta = 1;
         continue;
      }
      lcode = CodePattern.Match(icode,ifOBUvalue);
      if(lcode)
      {
         lcode = lcode - sizeof(OPC.ARG);
         nCode = Opcode.ExpandCode(lcode,nCode,sizeof(OPC.CNV));
         Opcode.SetLength(nCode);
         Opcode.SetOperation(codptr,lcode,OPC.CNV,OPC.CNV.CastBool);
         delta = 1;
         continue;
      }
      opcd = Opcode.GetOperation(codptr,icode,subc);
      if(opcd == OPC.NEW)
      {
         lastNew = icode;
         continue;
      }
      if(opcd == OPC.DPS && subc == getOBUToolTip)
      {
         nCode = Opcode.DeleteCode(icode,nCode,sizeof(OPC.DPS) - sizeof(OPC.OBU) - sizeof(OPC.MEM));
         Opcode.SetLength(nCode);
         Opcode.SetOperation(codptr,icode,OPC.OBU,OPC.OBU.ToolTipText);
         Opcode.SetOperation(codptr,icode+sizeof(OPC.OBU),OPC.MEM,OPC.MEM.Child);
         delta = 1;
         continue;
      }
      if(opcd == OPC.IOF && subc == OPC.IOF.Run)
      {
         Opcode.SetOperation(codptr,icode,OPC.WPO,OPC.WPO.RunProject);
         nCode = Opcode.ExpandCode(icode,nCode,sizeof(OPC.LDA));
         Opcode.SetLength(nCode);
         projInfo = Store.GetVector(projectRoot);
         Opcode.SetOperation(codptr,icode,OPC.LDA,projInfo.vbName);
         delta = 1;
         continue;
      }
      if((opcd == OPC.ANA && subc == OPC.ANA.DrawRectangle) ||
         (opcd == OPC.ANA && subc == OPC.ANA.FillRectangle) ||
         (opcd == OPC.PBX && subc == OPC.PBX.Line) )
      {
         nArg = Opcode.GetCallArgs(subRoot,lastNew,icode,qeAddr,qeType,8);
         iqe = Opcode.GetPrevious(codptr,qeAddr[6],qeAddr[7]-sizeof(OPC.ARG));
         opcd = Opcode.GetOperation(codptr,iqe,subc);
         if(opcd == OPC.CNV && subc == OPC.CNV.ColorToInt)
         {
            delta = 1;
            nCode = Opcode.DeleteCode(iqe,nCode,sizeof(OPC.CNV));
            Opcode.SetLength(nCode);
            icode = icode - sizeof(OPC.CNV);
         }
         continue;
      }
   }
   return delta;
}

int WPFRuntimeInformation(int projectRoot,int optValue)
{
   Project.Exename = Project.Startup; 
   if(!Project.StartupMain)
   {
      Project.Startup = "App";
   }
   return 0;
}

int WPFControlMigration(int ctlRoot,int iStart)
{
   int objType;

   objType = Store.GetObjectType(ctlRoot);
   if(objType == OPC.LIN) return ControlMigration.BlockControlAnalysis;
   return 0;
}

string WPFEventArgs(string source,int evtRoot)
{
   string ident;

   ident = Store.GetIdent(evtRoot);
   if(ident == "Resize")
   {
      if(source == "EventArgs") return "SizeChangedEventArgs";
   }
   else if(ident == "DropDown")
   {
      if(source == "EventArgs") return "EventArgs";
   }
   else if(ident == "Deactivate")
   {
      if(source == "EventArgs") return "EventArgs";
   }
   else if(ident == "Scroll")
   {
      if(source == "EventArgs") return "System.Windows.Controls.ScrollChangedEventArgs ";
   }
   else
   {
      if(source == "EventArgs") return "RoutedEventArgs";
      if(source == "System.Windows.Forms.MouseEventArgs") return "System.Windows.Input.MouseEventArgs";
      if(source == "System.Windows.Forms.KeyPressEventArgs") return "System.Windows.Input.KeyEventArgs";
      if(source == "System.Windows.Forms.KeyEventArgs") return "System.Windows.Input.KeyEventArgs";
      if(source == "System.Windows.Forms.ScrollEventArgs") return "System.Windows.Controls.Primitives.ScrollEventArgs";
   }
   return NULL;
}

int DriveListBox(int context,int ctlRoot,int topOffset)
{
   int    iCode;
   int    iProp;
   int    iValue;
   string eventName;
   int    eventRoot;
   int    ctlType;
   int    formRoot;

   if(context != EventType.AuthorSubsystem) return 0;
   for(formRoot = Store.GetParent(ctlRoot); formRoot != 0; formRoot = Store.GetParent(formRoot))
   {
      if(Store.GetObjectType(formRoot) == ObjectType.FormFile) break;
   }
   if(formRoot == 0) return 0;
   ctlType = Store.GetObjectType(ctlRoot);
   iCode = ControlData.LoadCode(ctlRoot);

   Write.Text("<my:DriveListBox");

   iCode = wrtCommonProperties(ctlRoot, ctlType, iCode, topOffset, 0);
   
   Write.Text(" />");
   Write.Record();
   
   Opcode.SetLength(iCode);
   return 1;
}

int DirListBox(int context,int ctlRoot,int topOffset)
{
   int    iCode;
   int    iProp;
   int    iValue;
   string eventName;
   int    eventRoot;
   int    ctlType;
   int    formRoot;
 
   if(context != EventType.AuthorSubsystem) return 0;
   for(formRoot = Store.GetParent(ctlRoot); formRoot != 0; formRoot = Store.GetParent(formRoot))
   {
      if(Store.GetObjectType(formRoot) == ObjectType.FormFile) break;
   }
   if(formRoot == 0) return 0;
   ctlType = Store.GetObjectType(ctlRoot);
   iCode = ControlData.LoadCode(ctlRoot);
   Write.Text("<my:DirListBox");

   iCode = wrtCommonProperties(ctlRoot, ctlType, iCode, topOffset, 0);
   
   Write.Text(" />");
   Write.Record();
   
   Opcode.SetLength(iCode);
   return 1;
}

string XAMLEncode(string str)
{
    int x;

    //The first 2 bytes are size of the string.  We need to strip them off.  They are being converted to ;\n.
    if (Character.FindFirst(str,0,";\n") == 1)
    {
        str = Character.SubStr(str,3);
    }

    //System.LogMessage("Encoding string: " + str);

    string s;
    string temp = "";
    string last = "";
    for (x = 0;x < 9999;x=x+1)
    {
        s = Character.SubStr(str,x,1);
        
        if (s == "&") 
        {
           //Temp fix for remove an wierd arrow character when finding &quot in the string
           //System.LogMessage("found:" + last);
           temp = Character.Replace(temp, last, "");
        }
        
        if (s == "")
        {
            break;
        }
        else
        {
            temp = temp + s;
        }
        last = s;
    }
    
    str = temp;
    
    str = Character.Replace(str, "\r\n", "&#10;");

    str = Character.Replace(str, "\r", "&#10;");
    str = Character.Replace(str, "\n", "&#13;");
    str = Character.Replace(str, "\t", "&#160;&#160;&#160;");
    
    return str;
}


    /***************************************************************************************************************************************************
                                                                        SplitMethods
    ***************************************************************************************************************************************************/
string Split(string str, string chr, int index)
{
    int cnt = 0;
    int pos = 0;
    int fnd = 0;
    string lastVal="";
    int lastPos = 0;
    
    //System.LogMessage("----------------------------------------");
    //System.LogMessage("Splitting Str: " + str + "  index: " + index);
    
    if (str == "")
    {
        //System.LogMessage("Empty string, dropping out");
        if (index == -1)
        {
            return 0;
        }
        else
        {
            return "";
        }
    }
    
    
    //System.LogMessage("First scan");
    
    fnd = Character.FindFirst(str,pos,chr);
    pos = pos + fnd;
    
    while (1)
    {
        //System.LogMessage("Entered loop");
    
        if (index == cnt) 
        {
            return Character.SubStr(str,lastPos,pos-lastPos-1);
        }
        
        cnt=cnt+1;
        
        fnd = Character.FindFirst(str,pos+1,chr);
        
        if (fnd == 0)
        {
            if (index == cnt) 
            {
                return Character.SubStr(str,pos);
            }
        
            if (pos-lastPos-1 > 1 && lastPos > 0)
            {
                //System.LogMessage("lastPos: " + lastPos + "  pos-lastPos-1: " + (pos-lastPos-1));
                cnt = cnt + 1;
            }
            
            //System.LogMessage("cnt: " + cnt);
            
            break;
        }
        lastPos = pos;
        pos = pos + fnd + 1;
    }
    
    if (index == -1)
    {
        //System.LogMessage("cnt: " + cnt);
        return cnt;
    }
    
    return 0;
}

string SplitCnt(string str, string chr)
{
    return Split(str, chr, -1);
}

int wpfCompilerInfo(int dummy1, int dummy2)
{
   if(Select.Dialect == Dialects.vbn)
   {
         //System.LogMessage("wpfCompilerInfo Reset subsystem sequence: wpb,wpf,lob,loc");
         Select.Subsystem = Dialects.wpb;
         Select.Subsystem2 = Dialects.wpf;
         Select.Subsystem3 = Dialects.lob;
         Select.Subsystem4 = Dialects.loc;
   }
   else
   {
         //System.LogMessage("wpfCompilerInfo Reset subsystem sequence: wpf,loc");
         Select.Subsystem = Dialects.wpf;
         Select.Subsystem2 = Dialects.loc;
   }
   return 0;
}

  • No labels