//-----------------------------------------------------------------------------
// wx.NET/Utils - WxFrameObject.cs
//
// wx.NET "WxFrameObject".
//
// Written by Alexander Olk (xenomorph2@onlinehome.de)
// (C) 2004 Alexander Olk
// Licensed under the wxWidgets license, see LICENSE.txt for details.
//
// $Id: WxFrameObject.cs,v 1.5 2004/06/14 19:56:36 t9mike Exp $
//-----------------------------------------------------------------------------
using System;
using System.Xml;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
namespace wx.ToWxNet{
public class WxFrameObject : WxRootObjectBase
{
public int frametype = 1; // 1 = normal frame, 2 = mdichildframe, mdichildframe is wxGlade only
public override void GenerateCSharpCode()
{
string baseclass = "Frame";
if ( frametype == 1 )
{
baseclass = "Frame";
}
else
{
baseclass = "MDIChildFrame";
}
linesout.Add( BetweenLine( 1 ) );
linesout.Add( " " );
// fix for XRC
if ( WxObjectBase.generateFromSource == 2 )
{
classname = name;
}
linesout.Add( "\tpublic class " + classname + " : " + baseclass );
linesout.Add( "\t{" );
// add IDs
if ( allIDs.Count > 0 )
{
regionIDS.Add( "\t\tpublic enum Cmd {" );
for ( int i = 0; i < allIDs.Count; i++ )
{
if ( i < ( allIDs.Count - 1 ) )
{
regionIDS.Add( "\t\t\t" + allIDs[i] + "," );
}
else
{
regionIDS.Add( "\t\t\t" + allIDs[i] );
}
}
regionIDS.Add( "\t\t}" );
}
// now add it to linesout...
linesout.Add( "\t\t" + doNotChangeCode );
linesout.Add( "\t\t#region \"TowxNET IDS: " + classname + "\"" );
foreach( string str in regionIDS )
{
linesout.Add( str );
}
linesout.Add( "\t\t#endregion" );
linesout.Add( " ");
linesout.Add( BetweenLine( 2 ) );
linesout.Add( " " );
// add wxObjects
if ( allObjs.Count > 0 )
{
for ( int i = 0; i < allObjs.Count; i++ )
{
regionObjects.Add( "\t\tprotected " + allObjs[i] + ";" );
}
}
// now add it to linesout...
linesout.Add( "\t\t" + doNotChangeCode );
linesout.Add( "\t\t#region \"TowxNET Objects: " + classname + "\"" );
foreach ( string str in regionObjects )
{
linesout.Add( str );
}
linesout.Add( "\t\t#endregion" );
linesout.Add( " " );
linesout.Add( BetweenLine( 2 ) );
linesout.Add( " " );
// ctor
linesout.Add( "\t\tpublic " + classname + "( Window parent, int id, string title )" );
StringBuilder basestring = new StringBuilder();
basestring.Append( "\t\t\t: base( parent, id , \"" + title + "\", wxDefaultPosition, " );
basestring.Append( size.Length > 0 ? "new Size( " + size + " )" : "wxDefaultSize" );
basestring.Append( ", " );
basestring.Append( style.Length > 0 ? style : "wxDEFAULT_FRAME_STYLE" );
basestring.Append( " )" );
linesout.Add( basestring.ToString() );
linesout.Add( "\t\t{" );
linesout.Add( "\t\t\tInitializeComponent();" );
linesout.Add( "\t\t}" );
linesout.Add( " " );
linesout.Add( BetweenLine( 2 ) );
linesout.Add( " " );
linesout.Add( "\t\t" + doNotChangeCode );
linesout.Add( "\t\t#region \"TowxNET CTOR: " + classname + "\"" );
// InitializeComponent()
regionCTOR.Add( "\t\tpublic void InitializeComponent()" );
regionCTOR.Add( "\t\t{" );
regionCTOR.Add( "\t\t\t//common" );
// add code from all objects to the common
AddCtorLines( objects, regionCTOR );
if ( wxToolBarObject != null)
if ( wxToolBarObject.ctorlines.Count > 0 )
{
for ( int i = 0; i < wxToolBarObject.ctorlines.Count; i++ )
{
regionCTOR.Add( wxToolBarObject.ctorlines[i] );
}
}
if ( wxStatusBarObject != null )
if ( wxStatusBarObject.ctorlines.Count > 0 )
{
for ( int i = 0; i < wxStatusBarObject.ctorlines.Count; i++ )
{
regionCTOR.Add( wxStatusBarObject.ctorlines[i] );
}
}
if ( wxMenuBarObject != null )
if ( wxMenuBarObject.ctorlines.Count > 0 )
{
for ( int i = 0; i < wxMenuBarObject.ctorlines.Count; i++ )
{
regionCTOR.Add( wxMenuBarObject.ctorlines[i] );
}
}
// ctor end
regionCTOR.Add( " " );
regionCTOR.Add( "\t\t\t//Properties" );
if ( wxStatusBarObject != null )
{
if ( wxStatusBarObject.propertylines.Count > 0 )
{
for ( int i = 0; i < wxStatusBarObject.propertylines.Count; i++ )
{
regionCTOR.Add( wxStatusBarObject.propertylines[i] );
}
}
}
if ( wxMenuBarObject != null )
{
if ( wxMenuBarObject.propertylines.Count > 0 )
{
for ( int i = 0; i < wxMenuBarObject.propertylines.Count; i++ )
{
regionCTOR.Add( wxMenuBarObject.propertylines[i] );
}
}
}
if ( wxToolBarObject != null )
{
if ( wxToolBarObject.propertylines.Count > 0 )
{
for ( int i = 0; i < wxToolBarObject.propertylines.Count; i++ )
{
regionCTOR.Add( wxToolBarObject.propertylines[i] );
}
}
}
AddPropertiesSelf( regionCTOR );
AddPropertyLinesSelf( regionCTOR );
AddPropertyLines( objects, regionCTOR );
regionCTOR.Add( " " );
regionCTOR.Add( "\t\t\t//Layout" );
AddLayoutLines( objects, regionCTOR );
// normally there should be at least one sizer
if ( WxObjectBase.topsizer != null )
{
regionCTOR.Add( "\t\t\tAutoLayout = true;" );
regionCTOR.Add( "\t\t\tSetSizer( " + WxObjectBase.topsizer.name + " );" );
regionCTOR.Add( "\t\t\tLayout();" );
}
if ( centered.Length > 0 )
{
regionCTOR.Add( "\t\t\tCentre();" );
}
regionCTOR.Add( "\t\t}" );
// now add it to linesout...
foreach ( string str in regionCTOR )
{
linesout.Add( str );
}
linesout.Add( "\t\t#endregion" );
linesout.Add( "\t}" );
linesout.Add( " " );
}
//---------------------------------------------------------------------
public override void GenerateBasicCode()
{
string baseclass = "Frame";
if ( frametype == 1 )
{
baseclass = "Frame";
}
else
{
baseclass = "MDIChildFrame";
}
linesout.Add( BetweenLine( 1 ) );
linesout.Add( " " );
// fix for XRC
if ( WxObjectBase.generateFromSource == 2 )
{
classname = name;
}
linesout.Add( "\tPublic Class " + classname );
linesout.Add( "\t\tInherits" + baseclass );
linesout.Add( " " );
// add IDs
if ( allIDs.Count > 0 )
{
regionIDS.Add( "\t\tPublic Enum Cmd" );
for ( int i = 0; i < allIDs.Count; i++ )
{
regionIDS.Add( "\t\t\t" + allIDs[i] );
}
regionIDS.Add( "\t\tEnd Enum" );
}
// now add it to linesout...
linesout.Add( "\t\t" + doNotChangeCode );
linesout.Add( "\t\t#region \"TowxNET IDS: " + classname + "\"");
foreach( string str in regionIDS )
{
linesout.Add( str );
}
linesout.Add( "\t\t#end region" );
linesout.Add( " ");
linesout.Add( BetweenLine( 2 ) );
linesout.Add( " " );
// add wxObjects
if ( allObjsBasic.Count > 0 )
{
for ( int i = 0; i < allObjsBasic.Count; i++ )
{
regionObjects.Add( "\t\tProtected WithEvents " + allObjsBasic[i] );
}
}
// now add it to linesout...
linesout.Add( "\t\t" + doNotChangeCode );
linesout.Add( "\t\t#region \"TowxNET Objects: " + classname + "\"");
foreach ( string str in regionObjects )
{
linesout.Add( str );
}
linesout.Add( "\t\t#end region" );
linesout.Add( " " );
linesout.Add( BetweenLine( 2 ) );
linesout.Add( " " );
// ctor
linesout.Add( "\t\tPublic Sub New( Optional ByVal parent As Window = Nothing, Optional ByVal id As Integer = -1, Optional ByVal title As String = \"" + title + "\")" );
StringBuilder basestring = new StringBuilder();
basestring.Append( "\t\t\tMyBase.New( parent, id, title, wxDefaultPosition, " );
basestring.Append( size.Length > 0 ? "New Size( " + size + " )" : "wxDefaultSize" );
basestring.Append( ", " );
basestring.Append( style.Length > 0 ? VBCorrectStyle(style) : "wxDEFAULT_FRAME_STYLE" );
basestring.Append( " )" );
linesout.Add( basestring.ToString() );
linesout.Add( " " );
linesout.Add( "\t\t\tInitializeComponent" );
linesout.Add( "\t\tEnd Sub" );
linesout.Add( " " );
linesout.Add( BetweenLine( 2 ) );
linesout.Add( " " );
linesout.Add( "\t\t" + doNotChangeCode );
linesout.Add( "\t\t#region \"TowxNET CTOR: " + classname + "\"");
regionCTOR.Add( "\t\tPublic Sub InitializeComponent()" );
regionCTOR.Add( " " );
regionCTOR.Add( "\t\t\t'common" );
// add code from all objects to the ctor
AddCtorLines( objects, regionCTOR );
if ( wxToolBarObject != null)
if ( wxToolBarObject.ctorlines.Count > 0 )
{
for ( int i = 0; i < wxToolBarObject.ctorlines.Count; i++ )
{
regionCTOR.Add( wxToolBarObject.ctorlines[i] );
}
}
if ( wxStatusBarObject != null )
if ( wxStatusBarObject.ctorlines.Count > 0 )
{
for ( int i = 0; i < wxStatusBarObject.ctorlines.Count; i++ )
{
regionCTOR.Add( wxStatusBarObject.ctorlines[i] );
}
}
if ( wxMenuBarObject != null )
if ( wxMenuBarObject.ctorlines.Count > 0 )
{
for ( int i = 0; i < wxMenuBarObject.ctorlines.Count; i++ )
{
regionCTOR.Add( wxMenuBarObject.ctorlines[i] );
}
}
// ctor end
regionCTOR.Add( " " );
regionCTOR.Add( "\t\t\t'Properties" );
if ( wxStatusBarObject != null )
{
if ( wxStatusBarObject.propertylines.Count > 0 )
{
for ( int i = 0; i < wxStatusBarObject.propertylines.Count; i++ )
{
regionCTOR.Add( wxStatusBarObject.propertylines[i] );
}
}
}
if ( wxMenuBarObject != null )
{
if ( wxMenuBarObject.propertylines.Count > 0 )
{
for ( int i = 0; i < wxMenuBarObject.propertylines.Count; i++ )
{
regionCTOR.Add( wxMenuBarObject.propertylines[i] );
}
}
}
if ( wxToolBarObject != null )
{
if ( wxToolBarObject.propertylines.Count > 0 )
{
for ( int i = 0; i < wxToolBarObject.propertylines.Count; i++ )
{
regionCTOR.Add( wxToolBarObject.propertylines[i] );
}
}
}
AddPropertiesSelf( regionCTOR );
AddPropertyLinesSelf( regionCTOR );
AddPropertyLines( objects, regionCTOR );
regionCTOR.Add( " " );
regionCTOR.Add( "\t\t\t'Layout" );
AddLayoutLines( objects, regionCTOR );
// normally there should be at least one sizer
if ( WxObjectBase.topsizer != null )
{
regionCTOR.Add( "\t\t\tAutoLayout = True" );
regionCTOR.Add( "\t\t\tSetSizer( " + WxObjectBase.topsizer.name + " )" );
regionCTOR.Add( "\t\t\tLayout()" );
}
if ( centered.Length > 0 )
{
regionCTOR.Add( "\t\t\tCentre()" );
}
regionCTOR.Add( "\t\tEnd Sub" );
// now add it to linesout...
foreach ( string str in regionCTOR )
{
linesout.Add( str );
}
linesout.Add( "\t\t#end region" );
linesout.Add( " " );
linesout.Add( "\tEnd Class" );
linesout.Add( " " );
}
}
}
|