Wiki

ListView.cs to ListView.cobra

ListView.cs:

//-----------------------------------------------------------------------------
// wx.NET/Samples - ListView.cs
//
// wx.NET "ListView" sample.
//
// Written by Alexander Olk (xenomorph2@onlinehome.de)
// (C) 2004 Alexander Olk
// Licensed under the wxWidgets license, see LICENSE.txt for details.
//
// $Id$
//-----------------------------------------------------------------------------

using System;
using System.Drawing;

namespace wx.SampleListView
{
    public class ListViewFrame : Frame
    {
        enum Cmd 
        {
            About,
            Quit
        }

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

        public TextCtrl textCtrl;

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

        public ListViewFrame(string title, Point pos, Size size)
            : base(title, pos, size)
        {
            // Set the window icon and status bar

            Icon = new wx.Icon("../Samples/ListView/mondrian.png");

            CreateStatusBar();
            StatusText = "Welcome to the ListView Sample!"; 
            
            Menu menuFile = new Menu();
            menuFile.AppendWL( (int)Cmd.About, "&About", new EventListener( OnAbout ) );
            menuFile.AppendSeparator();
            menuFile.AppendWL( (int)Cmd.Quit, "E&xit\tAlt-X", "Quit this program", new EventListener( OnQuit) );
            
            MenuBar menuBar = new MenuBar();
            menuBar.Append( menuFile, "&File" );
            MenuBar = menuBar;

            textCtrl = new TextCtrl(this, -1, "", wxDefaultPosition, wxDefaultSize, 
                TextCtrl.wxTE_MULTILINE | TextCtrl.wxTE_READONLY | TextCtrl.wxSUNKEN_BORDER );

            Log.SetActiveTarget( textCtrl );
            
            MyListView mlv = new MyListView( this );

            BoxSizer bSizer = new BoxSizer( Orientation.wxVERTICAL );
            bSizer.Add( mlv, 1, Stretch.wxGROW );
            bSizer.Add( textCtrl, 0, Stretch.wxGROW );

            Sizer = bSizer;
        }

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

        public void OnAbout( object sender, Event e )
        {
            MessageDialog.MessageBox( "wx.NET ListView sample\n2004 by Alexander Olk", "About",
                Dialog.wxOK | Dialog.wxICON_INFORMATION );
        }

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

        public void OnQuit( object sender, Event e )
        {
            Close();
        }
    }   
    
    //--------------------------------------------------------------------- 
    
    public class MyListView : ListView
    {
        public MyListView( Window parent )
            : base( parent, -1, wxDefaultPosition, wxDefaultSize, ListCtrl.wxLC_REPORT | ListCtrl.wxLC_EDIT_LABELS  )
        {
        
            InsertColumn( 0, "First Column" );
            SetColumnWidth( 0, 200 );
            
            ListItem itemCol = new ListItem();
            itemCol.Text = "Second Column";
            itemCol.Align = ListCtrl.wxLIST_FORMAT_CENTER;
            itemCol.Width = 300;
            InsertColumn( 1, itemCol );
        
            for ( int i = 0; i < 200; ++i )
            {
                string buf = "Col 1 Item " + i;
                int tmp = InsertItem( i, buf, 0);
                SetItemData( tmp, i );
                
                buf = "Col 2 Item " + i;
                SetItem( i, 1, buf );
            }
                
            Log.LogMessage( "Items created..." );
            
            ColumnClick += new EventListener( OnColumnClick );
            ItemSelect += new EventListener( OnItemSelect );
            ColumnRightClick += new EventListener( OnColumnRightClick );
        }
        
        //--------------------------------------------------------------------- 
        
        public void OnColumnClick( object sender, Event e )
        {
            ListEvent le = e as ListEvent;
            
            Log.LogMessage( "Clicked column header " + le.Column );
        }
        
        //--------------------------------------------------------------------- 
        
        public void OnItemSelect( object sender, Event e )
        {
            ListEvent le = e as ListEvent;
            
            Log.LogMessage( "Value 1st field of selected item: " + le.Text );
            
            ListItem info = new ListItem();
            info.Id = le.Index;
            info.Column = 1;
            info.Mask = ListCtrl.wxLIST_MASK_TEXT;
            
            GetItem( ref info );
            
            Log.LogMessage( "Value of 2nd field of selected item: " + info.Text );
        }
        
        //--------------------------------------------------------------------- 
        
        public void OnColumnRightClick( object sender, Event e )
        {
            ListEvent le = e as ListEvent;
            
            Log.LogMessage( "Right clicked column header " + le.Column );
        }
    }
    
    //--------------------------------------------------------------------- 

    public class ListViewApp : wx.App
    {
        public override bool OnInit()
        {
            ListViewFrame frame = new ListViewFrame("ListView wxWidgets Sample", new Point(10, 100), new Size(650,340));
            frame.Show(true);

            return true;
        }

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

        [STAThread]
        static void Main()
        {
            ListViewApp app = new ListViewApp();
            app.Run();
        }
    }
}

ListView.cobra:

/#-----------------------------------------------------------------------------
 wx.NET/Samples - ListView.cs

 wx.NET "ListView" sample.

 Written by Alexander Olk (xenomorph2@onlinehome.de)
 (C) 2004 Alexander Olk
 Licensed under the wxWidgets license, see LICENSE.txt for details.

 Converted to cobra hops 29-Oct-2009
 $Id$
-----------------------------------------------------------------------------
#/
use System.Drawing
use wx from "wx.NET"

namespace SampleListView
    class ListViewFrame inherits Frame

        enum Cmd 
            About
            Quit

        var textCtrl as TextCtrl

        cue init(title as String, pos as Point, size as Size)
            base.init(title, pos, size)
            # Set the window icon and status bar
            #Icon = Icon("./mondrian.png")) # this doesnt compile
            #.setIcon(Icon("./mondrian.png")) # nor this
            .createStatusBar
            #StatusText = "Welcome to the ListView Sample!" 
            #.statusText = "Welcome to the ListView Sample!"     # doesnt compile
            .setStatusText("Welcome to the ListView Sample!")
            
            menuFile = Menu()
            menuFile.appendWL( Cmd.About to int, "&About", EventListener( ref .onAbout ) )
            menuFile.appendSeparator
            menuFile.appendWL( Cmd.Quit to int, "E&xit\tAlt-X", "Quit this program", EventListener( ref .onQuit) )
            
            menuBar = MenuBar()
            menuBar.append( menuFile, "&File" )
            .menuBar = menuBar

            .textCtrl = TextCtrl(this, -1, "", .wxDefaultPosition, .wxDefaultSize, 
                TextCtrl.wxTE_MULTILINE | TextCtrl.wxTE_READONLY | TextCtrl.wxSUNKEN_BORDER )

            Log.setActiveTarget(.textCtrl)
            
            mlv = MyListView( this )

            bSizer = BoxSizer( Orientation.wxVERTICAL )
            bSizer.add( mlv, 1, Stretch.wxGROW )
            bSizer.add( .textCtrl, 0, Stretch.wxGROW )

            .sizer = bSizer
        

        def onAbout( sender as System.Object, e as Event)
            MessageDialog.messageBox( "wx.NET ListView sample (Cobra)\nConverted Oct 2009 by hops", "About",
                Dialog.wxOK | Dialog.wxICON_INFORMATION )
        
        def onQuit(sender, e as Event)
            .close
    
    class MyListView inherits ListView
    
        cue init( parent as Window )
            base.init( parent, -1, .wxDefaultPosition, .wxDefaultSize, ListCtrl.wxLC_REPORT | ListCtrl.wxLC_EDIT_LABELS  )
        
        
            .insertColumn( 0, "First Column" )
            .setColumnWidth( 0, 200 )
            
            itemCol = ListItem()
            itemCol.text = "Second Column"
            itemCol.align = ListCtrl.wxLIST_FORMAT_CENTER
            itemCol.width = 300
            .insertColumn( 1, itemCol )
        
            for i in 0 : 200
                buf = "Col 1 Item [i]"
                tmp = .insertItem( i, buf, 0)
                .setItemData( tmp, i )
                
                buf = "Col 2 Item [i]"
                .setItem( i, 1, buf )
                
            Log.logMessage( "Items created..." )

            listen .columnClick,    EventListener( ref .onColumnClick ) 
            #listen .columnClick,   ref .onColumnClick  # also works
            listen .itemSelect,       EventListener( ref .onItemSelect )
            listen .columnRightClick, EventListener( ref .onColumnRightClick )
        
        
        def onColumnClick( sender as System.Object, e as Event)
            le = e to ListEvent
            Log.logMessage( "Clicked column header [le.column]" )
        
        def onItemSelect( sender as System.Object, e as Event)
            le = e to ListEvent
            Log.logMessage( "Value 1st field of selected item: [le.text]" )

            info = ListItem()
            info.id = le.index
            info.column = 1
            info.mask = ListCtrl.wxLIST_MASK_TEXT
            .getItem( inout info ) 

            Log.logMessage( "Value of 2nd field of selected item: [info.text]" )

        def onColumnRightClick( sender as System.Object, e as Event )
            le = e to ListEvent
            Log.logMessage( "Right clicked column header [le.column]" )
        
    
    class ListViewApp inherits App is public
    
        def onInit as bool is override
            frame = ListViewFrame("ListView wxWidgets Sample", Point(10, 100), Size(650,340))
            frame.show(true)
            return true
        
        def main is shared has STAThread
            app = ListViewApp()
            app.run