ComboBox.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 = new ItemCollection(this);
  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. UpdateState = false;
  41. }
  42. internal override Gtk.Widget CreateWidget () {
  43. Gtk.Combo com1 = new Gtk.Combo();
  44. com1.SetPopdownStrings("");
  45. return com1;
  46. }
  47. public void Update () {
  48. ((Gtk.Combo)Widget).PopdownStrings = list;
  49. }
  50. public void BeginUpdate () {
  51. UpdateState = true;
  52. }
  53. public void EndUpdate () {
  54. UpdateState = false;
  55. Update();
  56. }
  57. public int FindString (string value){
  58. //return alist.BinarySearch(value);
  59. return alist.IndexOf(value);
  60. }
  61. public int SelectedIndex{
  62. get{
  63. return alist.IndexOf(((Gtk.Combo)Widget).Entry.Text);
  64. }
  65. set{
  66. ((Gtk.Combo)Widget).Entry.Text = (string)alist[value];
  67. }
  68. }
  69. public Object SelectedItem{
  70. get{
  71. return alist[this.SelectedIndex];
  72. }
  73. set{
  74. throw new NotImplementedException ();
  75. }
  76. }
  77. public int DropDownWidth {
  78. get {
  79. return menusize;
  80. }
  81. set {
  82. menusize = value;
  83. }
  84. }
  85. }
  86. }