ComboBox.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // System.Windows.Forms.ComboBox
  3. //
  4. // Author:
  5. // Joel Basson ([email protected])
  6. //
  7. //
  8. using System.Drawing;
  9. using System.Runtime.InteropServices;
  10. namespace System.Windows.Forms {
  11. /// <summary>
  12. /// Represents a Windows ComboBox control.
  13. ///
  14. /// </summary>
  15. public class ComboBox: Control{
  16. private int menusize;
  17. private bool UpdateState;
  18. public ItemCollection Items;
  19. GLib.List list = new GLib.List (IntPtr.Zero, typeof (string));
  20. System.Collections.ArrayList alist = new System.Collections.ArrayList();
  21. public class ItemCollection {
  22. ComboBox owner;
  23. public ItemCollection (ComboBox owner){
  24. this.owner = owner;
  25. }
  26. public void Add(String value){
  27. owner.alist.Add(value);
  28. owner.list.Append (Marshal.StringToHGlobalAnsi (value));
  29. if ( owner.UpdateState == false ) {owner.Update();}
  30. }
  31. public void AddRange(object[] items) {
  32. owner.alist.AddRange(items);
  33. foreach (object o in items)
  34. {string s = (string)o;
  35. owner.list.Append (Marshal.StringToHGlobalAnsi (s));}
  36. owner.Update();
  37. }
  38. }
  39. public ComboBox () : base (){
  40. Items = new ItemCollection(this);
  41. UpdateState = false;
  42. }
  43. internal override Gtk.Widget CreateWidget () {
  44. Gtk.Combo com1 = new Gtk.Combo();
  45. com1.SetPopdownStrings("");
  46. return com1;
  47. }
  48. public void Update () {
  49. ((Gtk.Combo)Widget).PopdownStrings = list;
  50. }
  51. public void BeginUpdate () {
  52. UpdateState = true;
  53. }
  54. public void EndUpdate () {
  55. UpdateState = false;
  56. Update();
  57. }
  58. public int FindString (string value){
  59. //return alist.BinarySearch(value);
  60. return alist.IndexOf(value);
  61. }
  62. public int SelectedIndex{
  63. get{
  64. return alist.IndexOf(((Gtk.Combo)Widget).Entry.Text);
  65. }
  66. set{
  67. ((Gtk.Combo)Widget).Entry.Text = (string)alist[value];
  68. }
  69. }
  70. public Object SelectedItem{
  71. get{
  72. return alist[this.SelectedIndex];
  73. }
  74. set{
  75. throw new NotImplementedException ();
  76. }
  77. }
  78. public int DropDownWidth {
  79. get {
  80. return menusize;
  81. }
  82. set {
  83. menusize = value;
  84. }
  85. }
  86. }
  87. }