| 1 | = !ListView.cs to !ListView.cobra = |
| 2 | |
| 3 | !ListView.cs: |
| 4 | {{{ |
| 5 | //----------------------------------------------------------------------------- |
| 6 | // wx.NET/Samples - ListView.cs |
| 7 | // |
| 8 | // wx.NET "ListView" sample. |
| 9 | // |
| 10 | // Written by Alexander Olk (xenomorph2@onlinehome.de) |
| 11 | // (C) 2004 Alexander Olk |
| 12 | // Licensed under the wxWidgets license, see LICENSE.txt for details. |
| 13 | // |
| 14 | // $Id$ |
| 15 | //----------------------------------------------------------------------------- |
| 16 | |
| 17 | using System; |
| 18 | using System.Drawing; |
| 19 | |
| 20 | namespace wx.SampleListView |
| 21 | { |
| 22 | public class ListViewFrame : Frame |
| 23 | { |
| 24 | enum Cmd |
| 25 | { |
| 26 | About, |
| 27 | Quit |
| 28 | } |
| 29 | |
| 30 | //--------------------------------------------------------------------- |
| 31 | |
| 32 | public TextCtrl textCtrl; |
| 33 | |
| 34 | //--------------------------------------------------------------------- |
| 35 | |
| 36 | public ListViewFrame(string title, Point pos, Size size) |
| 37 | : base(title, pos, size) |
| 38 | { |
| 39 | // Set the window icon and status bar |
| 40 | |
| 41 | Icon = new wx.Icon("../Samples/ListView/mondrian.png"); |
| 42 | |
| 43 | CreateStatusBar(); |
| 44 | StatusText = "Welcome to the ListView Sample!"; |
| 45 | |
| 46 | Menu menuFile = new Menu(); |
| 47 | menuFile.AppendWL( (int)Cmd.About, "&About", new EventListener( OnAbout ) ); |
| 48 | menuFile.AppendSeparator(); |
| 49 | menuFile.AppendWL( (int)Cmd.Quit, "E&xit\tAlt-X", "Quit this program", new EventListener( OnQuit) ); |
| 50 | |
| 51 | MenuBar menuBar = new MenuBar(); |
| 52 | menuBar.Append( menuFile, "&File" ); |
| 53 | MenuBar = menuBar; |
| 54 | |
| 55 | textCtrl = new TextCtrl(this, -1, "", wxDefaultPosition, wxDefaultSize, |
| 56 | TextCtrl.wxTE_MULTILINE | TextCtrl.wxTE_READONLY | TextCtrl.wxSUNKEN_BORDER ); |
| 57 | |
| 58 | Log.SetActiveTarget( textCtrl ); |
| 59 | |
| 60 | MyListView mlv = new MyListView( this ); |
| 61 | |
| 62 | BoxSizer bSizer = new BoxSizer( Orientation.wxVERTICAL ); |
| 63 | bSizer.Add( mlv, 1, Stretch.wxGROW ); |
| 64 | bSizer.Add( textCtrl, 0, Stretch.wxGROW ); |
| 65 | |
| 66 | Sizer = bSizer; |
| 67 | } |
| 68 | |
| 69 | //--------------------------------------------------------------------- |
| 70 | |
| 71 | public void OnAbout( object sender, Event e ) |
| 72 | { |
| 73 | MessageDialog.MessageBox( "wx.NET ListView sample\n2004 by Alexander Olk", "About", |
| 74 | Dialog.wxOK | Dialog.wxICON_INFORMATION ); |
| 75 | } |
| 76 | |
| 77 | //--------------------------------------------------------------------- |
| 78 | |
| 79 | public void OnQuit( object sender, Event e ) |
| 80 | { |
| 81 | Close(); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | //--------------------------------------------------------------------- |
| 86 | |
| 87 | public class MyListView : ListView |
| 88 | { |
| 89 | public MyListView( Window parent ) |
| 90 | : base( parent, -1, wxDefaultPosition, wxDefaultSize, ListCtrl.wxLC_REPORT | ListCtrl.wxLC_EDIT_LABELS ) |
| 91 | { |
| 92 | |
| 93 | InsertColumn( 0, "First Column" ); |
| 94 | SetColumnWidth( 0, 200 ); |
| 95 | |
| 96 | ListItem itemCol = new ListItem(); |
| 97 | itemCol.Text = "Second Column"; |
| 98 | itemCol.Align = ListCtrl.wxLIST_FORMAT_CENTER; |
| 99 | itemCol.Width = 300; |
| 100 | InsertColumn( 1, itemCol ); |
| 101 | |
| 102 | for ( int i = 0; i < 200; ++i ) |
| 103 | { |
| 104 | string buf = "Col 1 Item " + i; |
| 105 | int tmp = InsertItem( i, buf, 0); |
| 106 | SetItemData( tmp, i ); |
| 107 | |
| 108 | buf = "Col 2 Item " + i; |
| 109 | SetItem( i, 1, buf ); |
| 110 | } |
| 111 | |
| 112 | Log.LogMessage( "Items created..." ); |
| 113 | |
| 114 | ColumnClick += new EventListener( OnColumnClick ); |
| 115 | ItemSelect += new EventListener( OnItemSelect ); |
| 116 | ColumnRightClick += new EventListener( OnColumnRightClick ); |
| 117 | } |
| 118 | |
| 119 | //--------------------------------------------------------------------- |
| 120 | |
| 121 | public void OnColumnClick( object sender, Event e ) |
| 122 | { |
| 123 | ListEvent le = e as ListEvent; |
| 124 | |
| 125 | Log.LogMessage( "Clicked column header " + le.Column ); |
| 126 | } |
| 127 | |
| 128 | //--------------------------------------------------------------------- |
| 129 | |
| 130 | public void OnItemSelect( object sender, Event e ) |
| 131 | { |
| 132 | ListEvent le = e as ListEvent; |
| 133 | |
| 134 | Log.LogMessage( "Value 1st field of selected item: " + le.Text ); |
| 135 | |
| 136 | ListItem info = new ListItem(); |
| 137 | info.Id = le.Index; |
| 138 | info.Column = 1; |
| 139 | info.Mask = ListCtrl.wxLIST_MASK_TEXT; |
| 140 | |
| 141 | GetItem( ref info ); |
| 142 | |
| 143 | Log.LogMessage( "Value of 2nd field of selected item: " + info.Text ); |
| 144 | } |
| 145 | |
| 146 | //--------------------------------------------------------------------- |
| 147 | |
| 148 | public void OnColumnRightClick( object sender, Event e ) |
| 149 | { |
| 150 | ListEvent le = e as ListEvent; |
| 151 | |
| 152 | Log.LogMessage( "Right clicked column header " + le.Column ); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | //--------------------------------------------------------------------- |
| 157 | |
| 158 | public class ListViewApp : wx.App |
| 159 | { |
| 160 | public override bool OnInit() |
| 161 | { |
| 162 | ListViewFrame frame = new ListViewFrame("ListView wxWidgets Sample", new Point(10, 100), new Size(650,340)); |
| 163 | frame.Show(true); |
| 164 | |
| 165 | return true; |
| 166 | } |
| 167 | |
| 168 | //--------------------------------------------------------------------- |
| 169 | |
| 170 | [STAThread] |
| 171 | static void Main() |
| 172 | { |
| 173 | ListViewApp app = new ListViewApp(); |
| 174 | app.Run(); |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | }}} |
| 180 | |
| 181 | !ListView.cobra: |
| 182 | {{{ |
| 183 | /#----------------------------------------------------------------------------- |
| 184 | wx.NET/Samples - ListView.cs |
| 185 | |
| 186 | wx.NET "ListView" sample. |
| 187 | |
| 188 | Written by Alexander Olk (xenomorph2@onlinehome.de) |
| 189 | (C) 2004 Alexander Olk |
| 190 | Licensed under the wxWidgets license, see LICENSE.txt for details. |
| 191 | |
| 192 | Converted to cobra hops 29-Oct-2009 |
| 193 | $Id$ |
| 194 | ----------------------------------------------------------------------------- |
| 195 | #/ |
| 196 | use System.Drawing |
| 197 | use wx from "wx.NET" |
| 198 | |
| 199 | namespace SampleListView |
| 200 | class ListViewFrame inherits Frame |
| 201 | |
| 202 | enum Cmd |
| 203 | About |
| 204 | Quit |
| 205 | |
| 206 | var textCtrl as TextCtrl |
| 207 | |
| 208 | cue init(title as String, pos as Point, size as Size) |
| 209 | base.init(title, pos, size) |
| 210 | # Set the window icon and status bar |
| 211 | #Icon = Icon("./mondrian.png")) # this doesnt compile |
| 212 | #.setIcon(Icon("./mondrian.png")) # nor this |
| 213 | .createStatusBar |
| 214 | #StatusText = "Welcome to the ListView Sample!" |
| 215 | #.statusText = "Welcome to the ListView Sample!" # doesnt compile |
| 216 | .setStatusText("Welcome to the ListView Sample!") |
| 217 | |
| 218 | menuFile = Menu() |
| 219 | menuFile.appendWL( Cmd.About to int, "&About", EventListener( ref .onAbout ) ) |
| 220 | menuFile.appendSeparator |
| 221 | menuFile.appendWL( Cmd.Quit to int, "E&xit\tAlt-X", "Quit this program", EventListener( ref .onQuit) ) |
| 222 | |
| 223 | menuBar = MenuBar() |
| 224 | menuBar.append( menuFile, "&File" ) |
| 225 | .menuBar = menuBar |
| 226 | |
| 227 | .textCtrl = TextCtrl(this, -1, "", .wxDefaultPosition, .wxDefaultSize, |
| 228 | TextCtrl.wxTE_MULTILINE | TextCtrl.wxTE_READONLY | TextCtrl.wxSUNKEN_BORDER ) |
| 229 | |
| 230 | Log.setActiveTarget(.textCtrl) |
| 231 | |
| 232 | mlv = MyListView( this ) |
| 233 | |
| 234 | bSizer = BoxSizer( Orientation.wxVERTICAL ) |
| 235 | bSizer.add( mlv, 1, Stretch.wxGROW ) |
| 236 | bSizer.add( .textCtrl, 0, Stretch.wxGROW ) |
| 237 | |
| 238 | .sizer = bSizer |
| 239 | |
| 240 | |
| 241 | def onAbout( sender as System.Object, e as Event) |
| 242 | MessageDialog.messageBox( "wx.NET ListView sample (Cobra)\nConverted Oct 2009 by hops", "About", |
| 243 | Dialog.wxOK | Dialog.wxICON_INFORMATION ) |
| 244 | |
| 245 | def onQuit(sender, e as Event) |
| 246 | .close |
| 247 | |
| 248 | class MyListView inherits ListView |
| 249 | |
| 250 | cue init( parent as Window ) |
| 251 | base.init( parent, -1, .wxDefaultPosition, .wxDefaultSize, ListCtrl.wxLC_REPORT | ListCtrl.wxLC_EDIT_LABELS ) |
| 252 | |
| 253 | |
| 254 | .insertColumn( 0, "First Column" ) |
| 255 | .setColumnWidth( 0, 200 ) |
| 256 | |
| 257 | itemCol = ListItem() |
| 258 | itemCol.text = "Second Column" |
| 259 | itemCol.align = ListCtrl.wxLIST_FORMAT_CENTER |
| 260 | itemCol.width = 300 |
| 261 | .insertColumn( 1, itemCol ) |
| 262 | |
| 263 | for i in 0 : 200 |
| 264 | buf = "Col 1 Item [i]" |
| 265 | tmp = .insertItem( i, buf, 0) |
| 266 | .setItemData( tmp, i ) |
| 267 | |
| 268 | buf = "Col 2 Item [i]" |
| 269 | .setItem( i, 1, buf ) |
| 270 | |
| 271 | Log.logMessage( "Items created..." ) |
| 272 | |
| 273 | listen .columnClick, EventListener( ref .onColumnClick ) |
| 274 | #listen .columnClick, ref .onColumnClick # also works |
| 275 | listen .itemSelect, EventListener( ref .onItemSelect ) |
| 276 | listen .columnRightClick, EventListener( ref .onColumnRightClick ) |
| 277 | |
| 278 | |
| 279 | def onColumnClick( sender as System.Object, e as Event) |
| 280 | le = e to ListEvent |
| 281 | Log.logMessage( "Clicked column header [le.column]" ) |
| 282 | |
| 283 | def onItemSelect( sender as System.Object, e as Event) |
| 284 | le = e to ListEvent |
| 285 | Log.logMessage( "Value 1st field of selected item: [le.text]" ) |
| 286 | |
| 287 | info = ListItem() |
| 288 | info.id = le.index |
| 289 | info.column = 1 |
| 290 | info.mask = ListCtrl.wxLIST_MASK_TEXT |
| 291 | .getItem( inout info ) |
| 292 | |
| 293 | Log.logMessage( "Value of 2nd field of selected item: [info.text]" ) |
| 294 | |
| 295 | def onColumnRightClick( sender as System.Object, e as Event ) |
| 296 | le = e to ListEvent |
| 297 | Log.logMessage( "Right clicked column header [le.column]" ) |
| 298 | |
| 299 | |
| 300 | class ListViewApp inherits App is public |
| 301 | |
| 302 | def onInit as bool is override |
| 303 | frame = ListViewFrame("ListView wxWidgets Sample", Point(10, 100), Size(650,340)) |
| 304 | frame.show(true) |
| 305 | return true |
| 306 | |
| 307 | def main is shared has STAThread |
| 308 | app = ListViewApp() |
| 309 | app.run |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | }}} |