1 | /#----------------------------------------------------------------------------- |
---|
2 | wx.NET/Samples - ListView.cs |
---|
3 | |
---|
4 | wx.NET "ListView" sample. |
---|
5 | |
---|
6 | Written by Alexander Olk (xenomorph2@onlinehome.de) |
---|
7 | (C) 2004 Alexander Olk |
---|
8 | Licensed under the wxWidgets license, see LICENSE.txt for details. |
---|
9 | |
---|
10 | Converted to cobra hops 29-Oct-2009 |
---|
11 | $Id$ |
---|
12 | ----------------------------------------------------------------------------- |
---|
13 | #/ |
---|
14 | use System.Drawing |
---|
15 | use wx from "wx.NET" |
---|
16 | |
---|
17 | namespace SampleListView |
---|
18 | class ListViewFrame inherits Frame |
---|
19 | |
---|
20 | enum Cmd |
---|
21 | About |
---|
22 | Quit |
---|
23 | |
---|
24 | var textCtrl as TextCtrl |
---|
25 | |
---|
26 | cue init(title as String, pos as Point, size as Size) |
---|
27 | base.init(title, pos, size) |
---|
28 | # Set the window icon and status bar |
---|
29 | #Icon = Icon("./mondrian.png")) # this doesnt compile |
---|
30 | #.setIcon(Icon("./mondrian.png")) # nor this |
---|
31 | .createStatusBar |
---|
32 | #StatusText = "Welcome to the ListView Sample!" |
---|
33 | #.statusText = "Welcome to the ListView Sample!" # doesnt compile |
---|
34 | .setStatusText("Welcome to the ListView Sample!") |
---|
35 | |
---|
36 | menuFile = Menu() |
---|
37 | menuFile.appendWL( Cmd.About to int, "&About", EventListener( ref .onAbout ) ) |
---|
38 | menuFile.appendSeparator |
---|
39 | menuFile.appendWL( Cmd.Quit to int, "E&xit\tAlt-X", "Quit this program", EventListener( ref .onQuit) ) |
---|
40 | |
---|
41 | menuBar = MenuBar() |
---|
42 | menuBar.append( menuFile, "&File" ) |
---|
43 | .menuBar = menuBar |
---|
44 | |
---|
45 | .textCtrl = TextCtrl(this, -1, "", .wxDefaultPosition, .wxDefaultSize, |
---|
46 | TextCtrl.wxTE_MULTILINE | TextCtrl.wxTE_READONLY | TextCtrl.wxSUNKEN_BORDER ) |
---|
47 | |
---|
48 | Log.setActiveTarget(.textCtrl) |
---|
49 | |
---|
50 | mlv = MyListView( this ) |
---|
51 | |
---|
52 | bSizer = BoxSizer( Orientation.wxVERTICAL ) |
---|
53 | bSizer.add( mlv, 1, Stretch.wxGROW ) |
---|
54 | bSizer.add( .textCtrl, 0, Stretch.wxGROW ) |
---|
55 | |
---|
56 | .sizer = bSizer |
---|
57 | |
---|
58 | |
---|
59 | def onAbout( sender as System.Object, e as Event) |
---|
60 | MessageDialog.messageBox( "wx.NET ListView sample (Cobra)\nConverted Oct 2009 by hops", "About", |
---|
61 | Dialog.wxOK | Dialog.wxICON_INFORMATION ) |
---|
62 | |
---|
63 | def onQuit(sender, e as Event) |
---|
64 | .close |
---|
65 | |
---|
66 | class MyListView inherits ListView |
---|
67 | |
---|
68 | cue init( parent as Window ) |
---|
69 | base.init( parent, -1, .wxDefaultPosition, .wxDefaultSize, ListCtrl.wxLC_REPORT | ListCtrl.wxLC_EDIT_LABELS ) |
---|
70 | |
---|
71 | |
---|
72 | .insertColumn( 0, "First Column" ) |
---|
73 | .setColumnWidth( 0, 200 ) |
---|
74 | |
---|
75 | itemCol = ListItem() |
---|
76 | itemCol.text = "Second Column" |
---|
77 | itemCol.align = ListCtrl.wxLIST_FORMAT_CENTER |
---|
78 | itemCol.width = 300 |
---|
79 | .insertColumn( 1, itemCol ) |
---|
80 | |
---|
81 | for i in 0 : 200 |
---|
82 | buf = "Col 1 Item [i]" |
---|
83 | tmp = .insertItem( i, buf, 0) |
---|
84 | .setItemData( tmp, i ) |
---|
85 | |
---|
86 | buf = "Col 2 Item [i]" |
---|
87 | .setItem( i, 1, buf ) |
---|
88 | |
---|
89 | Log.logMessage( "Items created..." ) |
---|
90 | |
---|
91 | listen .columnClick, EventListener( ref .onColumnClick ) |
---|
92 | #listen .columnClick, ref .onColumnClick # also works |
---|
93 | listen .itemSelect, EventListener( ref .onItemSelect ) |
---|
94 | listen .columnRightClick, EventListener( ref .onColumnRightClick ) |
---|
95 | |
---|
96 | |
---|
97 | def onColumnClick( sender as System.Object, e as Event) |
---|
98 | le = e to ListEvent |
---|
99 | Log.logMessage( "Clicked column header [le.column]" ) |
---|
100 | |
---|
101 | def onItemSelect( sender as System.Object, e as Event) |
---|
102 | le = e to ListEvent |
---|
103 | Log.logMessage( "Value 1st field of selected item: [le.text]" ) |
---|
104 | |
---|
105 | info = ListItem() |
---|
106 | info.id = le.index |
---|
107 | info.column = 1 |
---|
108 | info.mask = ListCtrl.wxLIST_MASK_TEXT |
---|
109 | .getItem( inout info ) |
---|
110 | |
---|
111 | Log.logMessage( "Value of 2nd field of selected item: [info.text]" ) |
---|
112 | |
---|
113 | def onColumnRightClick( sender as System.Object, e as Event ) |
---|
114 | le = e to ListEvent |
---|
115 | Log.logMessage( "Right clicked column header [le.column]" ) |
---|
116 | |
---|
117 | |
---|
118 | class ListViewApp inherits App is public |
---|
119 | |
---|
120 | def onInit as bool is override |
---|
121 | frame = ListViewFrame("ListView wxWidgets Sample", Point(10, 100), Size(650,340)) |
---|
122 | frame.show(true) |
---|
123 | return true |
---|
124 | |
---|
125 | def main is shared has STAThread |
---|
126 | app = ListViewApp() |
---|
127 | app.run |
---|
128 | |
---|
129 | |
---|
130 | |
---|