/Samples/ListView/ListView.d

http://github.com/afb/wxd · D · 182 lines · 111 code · 48 blank · 23 comment · 2 complexity · 7b62bba3bbc72308e9fbee08509c6e43 MD5 · raw file

  1. //-----------------------------------------------------------------------------
  2. // wxD/Samples - ListView.cs
  3. //
  4. // wxD "ListView" sample.
  5. //
  6. // Written by Alexander Olk (xenomorph2@onlinehome.de)
  7. // Modified by BERO <berobero@users.sourceforge.net>
  8. // (C) 2004 Alexander Olk
  9. // Licensed under the wxWidgets license, see LICENSE.txt for details.
  10. //
  11. // $Id$
  12. //-----------------------------------------------------------------------------
  13. import wx.wx;
  14. private import std.string;
  15. static if (__VERSION__ >= 2050) {
  16. import std.conv : to;
  17. version(D_Version2) mixin("alias to!string toString;");
  18. }
  19. public class ListViewFrame : Frame
  20. {
  21. enum Cmd
  22. {
  23. About,
  24. Quit
  25. }
  26. //---------------------------------------------------------------------
  27. public TextCtrl textCtrl;
  28. //---------------------------------------------------------------------
  29. public this(string title, Point pos, Size size)
  30. {
  31. super(title, pos, size);
  32. // Set the window icon and status bar
  33. this.icon = new Icon("../Samples/ListView/mondrian.png");
  34. CreateStatusBar();
  35. StatusText = "Welcome to the ListView Sample!";
  36. Menu menuFile = new Menu();
  37. menuFile.AppendWL( Cmd.About, "&About", & OnAbout ) ;
  38. menuFile.AppendSeparator();
  39. menuFile.AppendWL( Cmd.Quit, "E&xit\tAlt-X", "Quit this program", & OnQuit) ;
  40. MenuBar menuBar = new MenuBar();
  41. menuBar.Append( menuFile, "&File" );
  42. this.menuBar = menuBar;
  43. textCtrl = new TextCtrl(this, -1, "", wxDefaultPosition, wxDefaultSize,
  44. TextCtrl.wxTE_MULTILINE | TextCtrl.wxTE_READONLY | TextCtrl.wxSUNKEN_BORDER );
  45. Log.SetActiveTarget( textCtrl );
  46. MyListView mlv = new MyListView( this );
  47. BoxSizer bSizer = new BoxSizer( Orientation.wxVERTICAL );
  48. bSizer.Add( mlv, 1, Stretch.wxGROW );
  49. bSizer.Add( textCtrl, 0, Stretch.wxGROW );
  50. this.sizer = bSizer;
  51. }
  52. //---------------------------------------------------------------------
  53. public void OnAbout( Object sender, Event e )
  54. {
  55. MessageBox( "wxD ListView sample\n2004 by Alexander Olk", "About",
  56. Dialog.wxOK | Dialog.wxICON_INFORMATION );
  57. }
  58. //---------------------------------------------------------------------
  59. public void OnQuit( Object sender, Event e )
  60. {
  61. Close();
  62. }
  63. }
  64. //---------------------------------------------------------------------
  65. public class MyListView : ListView
  66. {
  67. public this( Window parent )
  68. {
  69. super( parent, -1, wxDefaultPosition, wxDefaultSize, ListCtrl.wxLC_REPORT | ListCtrl.wxLC_EDIT_LABELS );
  70. InsertColumn( 0, "First Column" );
  71. SetColumnWidth( 0, 200 );
  72. ListItem itemCol = new ListItem();
  73. itemCol.Text = "Second Column";
  74. itemCol.Align = ListCtrl.wxLIST_FORMAT_CENTER;
  75. itemCol.Width = 300;
  76. InsertColumn( 1, itemCol );
  77. for ( int i = 0; i < 200; ++i )
  78. {
  79. string buf = "Col 1 Item " ~ .toString(i);
  80. int tmp = InsertItem( i, buf, 0);
  81. SetItemData( tmp, i );
  82. buf = "Col 2 Item " ~ .toString(i);
  83. SetItem( i, 1, buf );
  84. }
  85. Log.LogMessage( "Items created..." );
  86. ColumnClick_Add(& OnColumnClick );
  87. ItemSelect_Add(& OnItemSelect );
  88. ColumnRightClick_Add(& OnColumnRightClick );
  89. }
  90. //---------------------------------------------------------------------
  91. public void OnColumnClick( Object sender, Event e )
  92. {
  93. ListEvent le = cast(ListEvent)e;
  94. Log.LogMessage( "Clicked column header " ~ .toString(le.Column) );
  95. }
  96. //---------------------------------------------------------------------
  97. public void OnItemSelect( Object sender, Event e )
  98. {
  99. ListEvent le = cast(ListEvent)e;
  100. Log.LogMessage( "Value 1st field of selected item: " ~ le.Text );
  101. ListItem info = new ListItem();
  102. info.Id = le.Index;
  103. info.Column = 1;
  104. info.Mask = ListCtrl.wxLIST_MASK_TEXT;
  105. GetItem( info );
  106. Log.LogMessage( "Value of 2nd field of selected item: " ~ info.Text );
  107. }
  108. //---------------------------------------------------------------------
  109. public void OnColumnRightClick( Object sender, Event e )
  110. {
  111. ListEvent le = cast(ListEvent)e;
  112. Log.LogMessage( "Right clicked column header " ~ .toString(le.Column) );
  113. }
  114. }
  115. //---------------------------------------------------------------------
  116. public class ListViewApp : App
  117. {
  118. public override bool OnInit()
  119. {
  120. ListViewFrame frame = new ListViewFrame("ListView wxWidgets Sample", Point(10, 100), Size(650,340));
  121. frame.Show(true);
  122. return true;
  123. }
  124. //---------------------------------------------------------------------
  125. static void Main()
  126. {
  127. ListViewApp app = new ListViewApp();
  128. app.Run();
  129. }
  130. }
  131. void main(char[][] argv)
  132. {
  133. ListViewApp.Main();
  134. }