1e6fd6cf25b5dc352e1dad3a81ddcba8a42155f5
[mono.git] / mcs / class / System.Windows.Forms / System.Windows.Forms / ComboBox.cs
1 //
2 // System.Windows.Forms.ComboBox.cs
3 //
4 // Author:
5 //   stubbed out by Jaak Simm (jaaksimm@firm.ee)
6 //   Dennis Hayes (dennish@Raytek.com)
7 //       Alexandre Pigolkine (pigolkine@gmx.de)
8 //
9 // (C) Ximian, Inc., 2002/3
10 //
11
12 using System.ComponentModel;
13 using System.Collections;
14 using System.Drawing;
15 using System.Runtime.InteropServices;
16
17 namespace System.Windows.Forms {
18
19         /// <summary>
20         /// Represents a Windows combo box control.
21         /// </summary>
22
23         [MonoTODO]
24         public class ComboBox : ListControl {
25
26                 // private fields
27                 DrawMode drawMode;
28                 ComboBoxStyle dropDownStyle;
29                 bool droppedDown;
30                 bool integralHeight;
31                 bool sorted;
32                 Image backgroundImage;
33                 ControlStyles controlStyles;
34                 int selectedLength;
35                 string selectedText;
36                 int selectedIndex;
37                 object selectedItem;
38                 int selecedStart;
39                 private ComboBox.ObjectCollection Items_ = null;
40                 int itemHeight_;
41                 int maxDropDownItems;
42
43                 bool updateing; // true when begin update has been called. do not paint when true;
44                 // --- Constructor ---
45                 public ComboBox() : base() 
46                 {
47                         selectedLength = 0;
48                         selectedText = "";
49                         selectedIndex = -1;
50                         selectedItem = null;
51                         selecedStart = 0;
52                         updateing = false;
53                         //controlStyles = null;
54                         drawMode = DrawMode.Normal;
55                         dropDownStyle = ComboBoxStyle.DropDown;
56                         droppedDown = false;
57                         integralHeight = true;
58                         sorted = false;
59                         backgroundImage = null;
60                         Items_ = new ComboBox.ObjectCollection(this);
61                         itemHeight_ = 13;
62                         maxDropDownItems = 8;
63                         SubClassWndProc_ = true;
64
65                         Size = DefaultSize;
66                 }
67                 
68                 // --- Properties ---
69                 [MonoTODO]
70                 public override Color BackColor {
71                         get { 
72                                 return base.BackColor;
73                         }
74                         set { 
75                                 if(BackColor.A != 255){
76                                         if(
77                                                 (controlStyles & ControlStyles.SupportsTransparentBackColor) != 
78                                                 ControlStyles.SupportsTransparentBackColor 
79                                                 ){
80                                                 throw new 
81                                                         ArgumentOutOfRangeException("BackColor", BackColor, "Transparant background color not allowed.");
82                                         }
83                                 }
84                                 base.BackColor = value;
85                         }
86                 }
87                 
88                 public override Image BackgroundImage {
89                         get {
90                                 return backgroundImage; 
91                         }
92                         set { 
93                                 backgroundImage = value;
94                         }
95                 }
96                 
97                 internal int getDropDownHeight() {
98                         // FIXME: use PreferredHeight instead of DefaultSize.Height ?
99                         // FIXME: those calculations probably wrong
100                         return DefaultSize.Height + (maxDropDownItems + 1) * itemHeight_ - (itemHeight_ / 2);
101                 }
102
103                 [MonoTODO]
104                 protected override CreateParams CreateParams {
105                         get {
106                                         CreateParams createParams = base.CreateParams;
107
108                                         createParams.ClassName = "ComboBox";
109
110                                         if( DropDownStyle == ComboBoxStyle.Simple) {
111                                                 createParams.Height = Height;
112                                         }
113                                         else {
114                                                 createParams.Height = getDropDownHeight();
115                                         }
116
117                                         createParams.ExStyle = (int)( WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_NOPARENTNOTIFY);
118
119                                         createParams.Style = (int) (
120                                                 (int)WindowStyles.WS_CHILD | 
121                                                 (int)WindowStyles.WS_VISIBLE |
122                                                 (int)WindowStyles.WS_VSCROLL |
123                                                 (int)WindowStyles.WS_TABSTOP |
124                                                 (int)ComboBoxStyles.CBS_HASSTRINGS );
125
126                                         switch( DrawMode){
127                                                 case DrawMode.OwnerDrawFixed:
128                                                         createParams.Style |= (int)ComboBoxStyles.CBS_OWNERDRAWFIXED;
129                                                         break;
130                                                 case DrawMode.OwnerDrawVariable:
131                                                         createParams.Style |= (int)ComboBoxStyles.CBS_OWNERDRAWVARIABLE;
132                                                         break;
133                                         }
134
135                                         switch(DropDownStyle) {
136                                                 case ComboBoxStyle.Simple:
137                                                         createParams.Style |= (int)ComboBoxStyles.CBS_SIMPLE;
138                                                         break;
139                                                 case ComboBoxStyle.DropDown:
140                                                         createParams.Style |= (int)ComboBoxStyles.CBS_DROPDOWN;
141                                                         break;
142                                                 case ComboBoxStyle.DropDownList:
143                                                         createParams.Style |= (int)ComboBoxStyles.CBS_DROPDOWNLIST;
144                                                         break;
145                                         }
146                                         if( !integralHeight) {
147                                                 createParams.Style |= (int)ComboBoxStyles.CBS_NOINTEGRALHEIGHT;
148                                         }
149 /*
150  *      Keep Control unsorted, but sort data in Items (ArrayList)
151                                         if( sorted) {
152                                                 createParams.Style |= (int)ComboBoxStyles.CBS_SORT;
153                                         }
154 */
155                                         return createParams;
156                         }               
157                 }
158                 
159                 protected override Size DefaultSize {
160                         get {
161                                 return new Size(121,21);//correct size
162                         }
163                 }
164 /*
165                 public new Size Size {
166                         //FIXME: should we return client size or someother size???
167                         get {
168                                 return base.Size;
169                         }
170                         set {
171
172                                 if( dropDownStyle == ComboBoxStyle.Simple) {
173                                         Size sz = value;
174                                         sz.Height += maxDropDownItems * itemHeight_;
175                                         base.Size = sz;
176                                 }
177                                 else {
178                                         base.Size = value;
179                                 }
180                         }
181                 }
182 */
183                 public DrawMode DrawMode {
184                         get {
185                                 return drawMode;
186                         }
187                         set {
188                                 if( drawMode != value) {
189                                         drawMode = value;
190                                         RecreateHandle();
191                                 }
192                         }
193                 }
194
195                 public ComboBoxStyle DropDownStyle {
196                         get {
197                                 return dropDownStyle;
198                         }
199                         set {
200                                 if( dropDownStyle != value) {
201                                         dropDownStyle = value;
202                                         RecreateHandle();
203                                         OnDropDownStyleChanged( new EventArgs());
204                                 }
205                         }
206                 }
207                 
208                 [MonoTODO]
209                 public int DropDownWidth {
210                         get {
211                                 throw new NotImplementedException ();
212                         }
213                         set {
214                                 //FIXME:
215                         }
216                 }
217                 
218                 public bool DroppedDown {
219                         get { 
220                                 return droppedDown;
221                         }
222                         set {
223                                 droppedDown = value; 
224                         }
225                 }
226                 
227                 [MonoTODO]
228                 public override bool Focused {
229                         get {
230                                 if (IsHandleCreated) {
231                                         IntPtr focusedWindow = Win32.GetFocus();
232                                         if (focusedWindow == Handle)
233                                                 return true;
234                                         if( Win32.GetParent(focusedWindow) == Handle)
235                                                 return true;
236                                 }
237                                 return false;
238                         }
239                 }
240                 
241                 [MonoTODO]
242                 public override Color ForeColor {
243                         get {
244                                 //FIXME: 
245                                 return base.ForeColor;
246                         }
247                         set {
248                                 //FIXME: 
249                                 base.ForeColor = value;
250                         }
251                 }
252                 
253                 public bool IntegralHeight {
254                         get {
255                                 return integralHeight;
256                         }
257                         set {
258                                 if( integralHeight != value) {
259                                         integralHeight = value;
260                                         if( IsHandleCreated) {
261                                                 if( integralHeight) {
262                                                         Win32.UpdateWindowStyle(Handle, (int)ComboBoxStyles.CBS_NOINTEGRALHEIGHT, 0);
263                                                 }
264                                                 else {
265                                                         Win32.UpdateWindowStyle(Handle, 0, (int)ComboBoxStyles.CBS_NOINTEGRALHEIGHT);
266                                                 }
267                                         }
268                                 }
269                         }
270                 }
271                 
272                 [MonoTODO]
273                 public int ItemHeight {
274                         get {
275                                 return itemHeight_;
276                         }
277                         set {
278                                 itemHeight_ = value;
279                                 if( IsHandleCreated) {
280                                         if( DrawMode != DrawMode.OwnerDrawVariable) {
281                                                 Win32.SendMessage(Handle, (int)ComboBoxMessages.CB_SETITEMHEIGHT, 0, itemHeight_);
282                                         }
283                                         else {
284                                                 for( int i = 0; i < Items.Count; i++) {
285                                                         Win32.SendMessage(Handle, (int)ComboBoxMessages.CB_SETITEMHEIGHT, i, itemHeight_);
286                                                 }
287                                         }
288                                         Win32.SendMessage(Handle, (int)ComboBoxMessages.CB_SETITEMHEIGHT, -1, itemHeight_);
289                                 }
290                         }
291                 }
292                 
293                 [MonoTODO]
294                 public ComboBox.ObjectCollection Items {
295                         get { 
296                                 return Items_; 
297                         }
298                 }
299                 
300                 [MonoTODO]
301                 public int MaxDropDownItems {
302                         get {
303                                 return maxDropDownItems;
304                         }
305                         set {
306                                 if( maxDropDownItems != value) {
307                                         maxDropDownItems = value;
308                                         if( DropDownStyle != ComboBoxStyle.Simple) {
309                                                 Height = getDropDownHeight();
310                                         }
311                                 }
312                         }
313                 }
314                 
315                 [MonoTODO]
316                 public int MaxLength {
317                         get {
318                                 throw new NotImplementedException ();
319                         }
320                         set {
321                                 //FIXME:                
322                         }
323                 }
324                 
325                 [MonoTODO]
326                 public int PreferredHeight {
327                         get {
328                                 return 20; //FIXME: this is the default, good as any?
329                         }
330                 }
331         
332                 [MonoTODO]
333                 public override int SelectedIndex {
334                         get {
335                                 if( IsHandleCreated) {
336                                         return Win32.SendMessage(Handle, (int)ComboBoxMessages.CB_GETCURSEL, 0, 0);
337                                 }
338                                 else {
339                                         return selectedIndex;
340                                 }
341                         }
342                         set {
343                                 if( selectedIndex != value) {
344                                         //FIXME: set exception parameters
345                                         if( value >= Items_.Count) {
346                                                 throw new ArgumentOutOfRangeException();
347                                         }
348                                         selectedIndex = value;
349                                         if( IsHandleCreated) {
350                                                 Win32.SendMessage(Handle, (int)ComboBoxMessages.CB_SETCURSEL, selectedIndex, 0);
351                                         }
352                                         OnSelectedIndexChanged(new EventArgs());
353                                 }
354                         }
355                 }
356                 
357                 [MonoTODO]
358                 public object SelectedItem {
359                         get {
360                                 if( IsHandleCreated) {
361                                         return Items_[Win32.SendMessage(Handle, (int)ComboBoxMessages.CB_GETCURSEL, 0, 0)];
362                                 }
363                                 else {
364                                         return Items_[selectedIndex];
365                                 }
366                         }
367                         set { 
368                                 //FIXME:
369                         }
370                 }
371                 
372                 [MonoTODO]
373                 public string SelectedText {
374                         get { 
375                                 throw new NotImplementedException ();
376                         }
377                         set {
378                                 //FIXME:
379                         }
380                 }
381                 
382                 [MonoTODO]
383                 public int SelectionLength {
384                         get {
385                                 throw new NotImplementedException ();
386                         }
387                         set {
388                                 //FIXME:
389                         }
390                 }
391                 
392                 [MonoTODO]
393                 public int SelectionStart {
394                         get {
395                                 throw new NotImplementedException ();
396                         }
397                         set {
398                                 //FIXME:
399                         }
400                 }
401                 
402                 public bool Sorted {
403                         get {
404                                 return sorted;
405                         }
406                         set {
407                                 if( sorted != value) {
408                                         sorted = value;
409                                         if( IsHandleCreated) {
410                                                 if( sorted) {
411                                                         object[] items = new object[Items.Count];
412                                                         Items.CopyTo(items, 0);
413                                                         Items.Clear();
414                                                         Items.AddRange(items);
415                                                 }
416                                         }
417                                         selectedIndex = -1;
418                                 }
419                         }
420                 }
421                 
422                 [MonoTODO]
423                 public override string Text {
424                         get {
425                                 return base.Text;
426                         }
427                         set {
428                                 base.Text = value;
429                                 if (value == null || value == String.Empty) {
430                                         SelectedIndex = -1;
431                                 }
432                         }
433                 }
434                 
435                 /// --- Methods ---
436                 /// internal .NET framework supporting methods, not stubbed out:
437
438                 internal void populateControl( ICollection items) {
439                         if( IsHandleCreated && items != null) {
440                                 foreach( object obj in items) {
441                                         // CHECKME : shall we check for null here or in Add/Insert functions
442                                         if( obj != null) {
443                                                 Win32.SendMessage(Handle, (int)ComboBoxMessages.CB_ADDSTRING, 0, getDisplayMemberOfObj(obj));
444                                         }
445                                 }
446                         }
447                 }
448
449                 protected override void Dispose(bool disposing) {
450                         base.Dispose(disposing);
451                 }
452
453                 [MonoTODO]
454                 protected override void OnSelectedValueChanged(EventArgs e){ // .NET V1.1 Beta
455                         //FIXME:
456                         base.OnSelectedValueChanged(e);
457                 }
458
459                 [MonoTODO]
460                 protected override void SetItemCore(int index,object value){
461                 }
462
463                 [MonoTODO]
464                 protected virtual void AddItemsCore(object[] value) {
465                         //FIXME:                
466                 }
467                 
468                 [MonoTODO]
469                 public void BeginUpdate() 
470                 {
471                         updateing = true;
472                 }
473                 
474                 [MonoTODO]
475                 public void EndUpdate() 
476                 {
477                         updateing = false;
478                 }
479                 
480                 [MonoTODO]
481                 public int FindString(string s) 
482                 {
483                         throw new NotImplementedException ();
484                 }
485                 
486                 [MonoTODO]
487                 public int FindString(string s,int startIndex) 
488                 {
489                         throw new NotImplementedException ();
490                 }
491                 
492                 [MonoTODO]
493                 public int FindStringExact(string s) 
494                 {
495                         throw new NotImplementedException ();
496                 }
497                 
498                 [MonoTODO]
499                 public int FindStringExact(string s,int startIndex) 
500                 {
501                         throw new NotImplementedException ();
502                 }
503                 
504                 [MonoTODO]
505                 public int GetItemHeight(int index) 
506                 {
507                         throw new NotImplementedException ();
508                 }
509                 
510                 [MonoTODO]
511                 protected override bool IsInputKey(Keys keyData) 
512                 {
513                         //FIXME:
514                         return base.IsInputKey(keyData);
515                 }
516                 
517                 /// [methods for events]
518                 [MonoTODO]
519                 protected override void OnBackColorChanged(EventArgs e) 
520                 {
521                         //FIXME:
522                         base.OnBackColorChanged(e);
523                 }
524                 
525                 [MonoTODO]
526                 protected override void OnDataSourceChanged(EventArgs e) 
527                 {
528                         //FIXME:
529                         base.OnDataSourceChanged(e);
530                 }
531                 
532                 [MonoTODO]
533                 protected override void OnDisplayMemberChanged(EventArgs e) 
534                 {
535                         //FIXME:
536                         base.OnDisplayMemberChanged(e);
537                 }
538                 
539                 [MonoTODO]
540                 protected virtual void OnDrawItem(DrawItemEventArgs e) 
541                 {
542                         if( DrawItem != null) {
543                                 DrawItem(this, e);
544                         }
545                 }
546                 
547                 [MonoTODO]
548                 protected virtual void OnDropDown(EventArgs e) 
549                 {
550                         //FIXME:                
551                 }
552                 
553                 [MonoTODO]
554                 protected virtual void OnDropDownStyleChanged(EventArgs e) 
555                 {
556                         if( DropDownStyleChanged != null) {
557                                 DropDownStyleChanged(this, e);
558                         }
559                 }
560                 
561                 [MonoTODO]
562                 protected override void OnFontChanged(EventArgs e) 
563                 {
564                         //FIXME:
565                         base.OnFontChanged(e);
566                 }
567                 
568                 [MonoTODO]
569                 protected override void OnForeColorChanged(EventArgs e) 
570                 {
571                         //FIXME:
572                         base.OnForeColorChanged(e);
573                 }
574                 
575                 [MonoTODO]
576                 protected override void OnHandleCreated(EventArgs e) 
577                 {
578                         //FIXME:
579                         base.OnHandleCreated(e);
580                         populateControl(Items_);
581                         if (DropDownStyle != ComboBoxStyle.DropDown || Text == String.Empty) {
582                                 if (selectedIndex == -1 && Items.Count != 0) {
583                                         selectedIndex = 0;
584                                 }
585                                 Win32.SendMessage(Handle, (int)ComboBoxMessages.CB_SETCURSEL, selectedIndex, 0);
586                         }
587                 }
588                 
589                 [MonoTODO]
590                 protected override void OnHandleDestroyed(EventArgs e) 
591                 {
592                         //FIXME:
593                         base.OnHandleDestroyed(e);
594                 }
595                 
596                 [MonoTODO]
597                 protected override void OnKeyPress(KeyPressEventArgs e) 
598                 {
599                         //FIXME:
600                         base.OnKeyPress(e);
601                 }
602                 
603                 [MonoTODO]
604                 protected virtual void OnMeasureItem(MeasureItemEventArgs e) 
605                 {
606                         if(MeasureItem != null) {
607                                 MeasureItem(this, e);
608                         }
609                 }
610                 
611                 [MonoTODO]
612                 protected override void OnParentBackColorChanged(EventArgs e) 
613                 {
614                         //FIXME:
615                         base.OnParentBackColorChanged(e);
616                 }
617                 
618                 [MonoTODO]
619                 protected override void OnResize(EventArgs e) 
620                 {
621                         //FIXME:
622                         base.OnResize(e);
623                 }
624                 
625                 [MonoTODO]
626                 protected override void OnSelectedIndexChanged(EventArgs e) 
627                 {
628                         if( SelectedIndexChanged != null) {
629                                 SelectedIndexChanged( this, e);
630                         }
631                 }
632
633                 [MonoTODO]
634                 protected virtual void OnSelectedItemChanged(EventArgs e) {
635                         
636                 }
637                 
638                 [MonoTODO]
639                 protected virtual void OnSelectionChangeCommitted(EventArgs e) 
640                 {
641                         //FIXME:                
642                 }
643                 /// end of [methods for events]
644                 
645                 
646                 [MonoTODO]
647                 protected override void RefreshItem(int index) 
648                 {
649                         //FIXME:
650                         base.Refresh();
651                 }
652                 
653                 [MonoTODO]
654                 public void Select(int start,int length) 
655                 {
656                         //FIXME:
657                 }
658                 
659                 [MonoTODO]
660                 public void SelectAll() 
661                 {
662                         //FIXME:
663                 }
664                 
665                 [MonoTODO]
666                 protected override void SetBoundsCore(int x,int y,int width,int height,BoundsSpecified specified) 
667                 {
668                         //FIXME:
669                         // If DropDownStyle == ComboBoxStyle.Simple, the heigth is a real window height - no control over it
670                         // else, 
671                         //              if Handle created - specify complete height, ComboBox-control will adjust window rectangle
672                         //                      else - set the height to Default.
673                         if(DropDownStyle != ComboBoxStyle.Simple) {
674                                 if( IsHandleCreated) {
675                                         height = getDropDownHeight();
676                                 }
677                                 else {
678                                         height = DefaultSize.Height;
679                                 }
680                         }
681                         if ( (specified & BoundsSpecified.X) == 0)      x = Left;
682                         if ( (specified & BoundsSpecified.Y) == 0)      y = Top;
683                         if ( (specified & BoundsSpecified.Width) == 0)  width = Width;
684                         //if ( (specified & BoundsSpecified.Height) == 0) height = Height;
685
686                         if (IsHandleCreated){
687                                 SetWindowPosFlags flags = SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_DRAWFRAME;
688                                 Win32.SetWindowPos (Handle, SetWindowPosZOrder.HWND_NOTOPMOST, x, y, width, height, flags);
689
690                                 RECT rect = new RECT();
691                                 Win32.GetWindowRect (Handle, ref rect);
692
693                                 if( Parent != null) {
694
695                                         Win32.ScreenToClient(Parent.Handle, ref rect);
696
697                                 }
698
699                                 x = rect.left;
700
701                                 y = rect.top;
702
703                                 width = rect.right - rect.left;
704
705                                 height = rect.bottom - rect.top;
706
707                         }
708
709                         UpdateBounds (x, y, width, height);
710
711                         // FIXME: this is needed, otherwise painting is not correct
712                         if( dropDownStyle == ComboBoxStyle.Simple ) {
713                                 Win32.InvalidateRect(Handle, IntPtr.Zero, 0);
714                                 Win32.UpdateWindow(Handle);
715                         }
716                 }
717                 
718                 // for IList interface
719                 // FIXME not sure how to handle this
720                 //[MonoTODO]
721                 //protected override void SetItemsCore(IList value) 
722                 //{
723                 //      throw new NotImplementedException ();
724                 //}
725                 
726                 [MonoTODO]
727                 public override string ToString() 
728                 {
729                         //FIXME:
730                         return base.ToString();
731                 }
732                 
733                 [MonoTODO]
734                 protected override void WndProc(ref Message m) 
735                 {
736                         switch ((Msg) m.Msg) {
737                                 case Msg.WM_MEASUREITEM: {
738                                         MEASUREITEMSTRUCT mis = new MEASUREITEMSTRUCT();
739                                         mis = (MEASUREITEMSTRUCT)Marshal.PtrToStructure(m.LParam, mis.GetType());
740                                         MeasureItemEventArgs args = new MeasureItemEventArgs(CreateGraphics(),mis.itemID);
741                                         args.ItemHeight = mis.itemHeight;
742                                         args.ItemWidth = mis.itemWidth;
743                                         OnMeasureItem( args);
744                                         mis.itemHeight = args.ItemHeight;
745                                         mis.itemWidth = args.ItemWidth;
746                                         Marshal.StructureToPtr(mis, m.LParam, false);
747                                         m.Result = (IntPtr)1;
748                                 }
749                                         break;
750                                 case Msg.WM_DRAWITEM: {
751                                         DRAWITEMSTRUCT dis = new DRAWITEMSTRUCT();
752                                         dis = (DRAWITEMSTRUCT)Marshal.PtrToStructure(m.LParam, dis.GetType());
753                                         Rectangle       rect = new Rectangle(dis.rcItem.left, dis.rcItem.top, dis.rcItem.right - dis.rcItem.left, dis.rcItem.bottom - dis.rcItem.top);
754                                         DrawItemEventArgs args = new DrawItemEventArgs(Graphics.FromHdc(dis.hDC), Font,
755                                                 rect, dis.itemID, (DrawItemState)dis.itemState);
756                                         OnDrawItem( args);
757                                         //Marshal.StructureToPtr(dis, m.LParam, false);
758                                         m.Result = (IntPtr)1;
759                                 }
760                                         break;
761 /*
762                                 case Msg.WM_COMPAREITEM: {
763                                         int i = 10;
764                                 }
765                                         break;
766 */                                      
767                                 case Msg.WM_COMMAND: 
768                                         if( m.LParam != Handle) {
769                                                 base.WndProc(ref m);
770                                         }
771                                         else {
772                                                 switch(m.HiWordWParam) {
773                                                         case (uint)ComboBoxNotification.CBN_SELCHANGE:
774                                                                 SelectedIndex = Win32.SendMessage(Handle, (int)ComboBoxMessages.CB_GETCURSEL, 0, 0);
775                                                                 m.Result = IntPtr.Zero;
776                                                                 break;
777                                                         default:
778                                                                 m.Result = IntPtr.Zero;
779                                                                 break;
780                                                 }
781                                         }
782                                         break;
783                                 case Msg.WM_CTLCOLOREDIT :
784                                         CallControlWndProc ( ref m );
785                                         break;
786                                 default:
787                                         base.WndProc(ref m);
788                                         break;
789                         }
790                 }
791                 
792                 [MonoTODO]
793                 protected override void SetItemsCore (IList value){
794                 }
795         
796                 /// --- Button events ---
797                 /// commented out, cause it only supports the .NET Framework infrastructure
798                 [MonoTODO]
799                 public event DrawItemEventHandler DrawItem;
800                 
801                 [MonoTODO]
802                 public event EventHandler DropDown;
803                 
804                 [MonoTODO]
805                 public event EventHandler DropDownStyleChanged;
806                 
807                 [MonoTODO]
808                 public event MeasureItemEventHandler MeasureItem;
809                 
810                 /* only supports .NET framework
811                         [MonoTODO]
812                         public new event PaintEventHandler Paint;
813                 */
814                 
815                 [MonoTODO]
816                 public event EventHandler SelectedIndexChanged;
817                 
818                 [MonoTODO]
819                 public event EventHandler SelectionChangeCommitted;
820                 
821                 [MonoTODO]
822                 public class ChildAccessibleObject : AccessibleObject {
823                 /// the class is not stubbed, cause it's only used for .NET framework
824                 
825                 }
826                 
827                 
828                 /// sub-class: ComboBox.ObjectCollection
829                 /// <summary>
830                 /// Represents the collection of items in a ComboBox.
831                 /// </summary>
832                 [MonoTODO]
833                 public class ObjectCollection : IList, ICollection, IEnumerable {
834                         private ArrayList collection_ = new ArrayList ();
835                         private ComboBox owner_ = null;
836                         
837                         /// --- ObjectCollection.constructor ---
838                         [MonoTODO]
839                         public ObjectCollection (ComboBox owner) {
840                                 owner_ = owner;
841                         }
842                         
843                         /// --- ObjectCollection Properties ---
844                         [MonoTODO]
845                         public int Count {
846                                 get { 
847                                         return collection_.Count;
848                                 }
849                         }
850                         
851                         [MonoTODO]
852                         public bool IsReadOnly {
853                                 get { 
854                                         return collection_.IsReadOnly;
855                                 }
856                         }
857
858                         object IList.this[int index] {
859                                 get { return collection_[index]; }
860                                 set { collection_[index] = value; }
861                         }
862                                                 
863                         [MonoTODO]
864                         public object this[int index] {
865                                 get { return collection_[index]; }
866                                 set { collection_[index] = value; }
867                         }
868
869                         /// --- ICollection properties ---
870
871                         bool IList.IsFixedSize {
872                                 [MonoTODO] get { return collection_.IsFixedSize; }
873                         }
874
875
876                         object ICollection.SyncRoot {
877                                 get { return collection_.SyncRoot; }
878                         }
879         
880                         bool ICollection.IsSynchronized {
881
882                                 [MonoTODO] get { return collection_.IsSynchronized; }
883                         }
884                         
885                         /// --- methods ---
886                         /// --- ObjectCollection Methods ---
887                         /// Note: IList methods are stubbed out, otherwise IList interface cannot be implemented
888                         [MonoTODO]
889                         public int Add(object item) {
890                                 // FIXME: not optimal 
891                                 int idx = collection_.Add(item);
892                                 if( owner_.Sorted) {
893                                         ListControl.ListControlComparer cic = new ListControl.ListControlComparer(owner_);
894                                         collection_.Sort(cic);
895                                         idx = collection_.BinarySearch(item,cic);
896                                         if( owner_.IsHandleCreated) {
897                                                 Win32.SendMessage(owner_.Handle, (int)ComboBoxMessages.CB_INSERTSTRING, idx, owner_.getDisplayMemberOfObj(item));
898                                         }
899                                 }
900                                 else {
901                                         if( owner_.IsHandleCreated) {
902                                                 Win32.SendMessage(owner_.Handle, (int)ComboBoxMessages.CB_ADDSTRING, 0, owner_.getDisplayMemberOfObj(item));
903                                         }
904                                 }
905                                 return idx;
906                         }
907                         
908                         [MonoTODO]
909                         public void AddRange(object[] items) 
910                         {
911                                 // FIXME: not optimal 
912                                 foreach(object item in items) {
913                                         Add(item);
914                                 }
915 //                              owner_.populateControl(items);
916 //                              collection_.AddRange(items);
917                         }
918                         
919                         [MonoTODO]
920                         public void Clear() 
921                         {
922                                 collection_.Clear();
923                                 Win32.SendMessage(owner_.Handle, (int)ComboBoxMessages.CB_RESETCONTENT, 0, 0);
924                         }
925                         
926                         [MonoTODO]
927                         public bool Contains(object value) 
928                         {
929                                 return collection_.Contains(value);
930                         }
931                         
932                         [MonoTODO]
933                         public void CopyTo(object[] dest,int arrayIndex) 
934                         {
935                                 collection_.CopyTo(dest, arrayIndex);
936                         }
937                         
938                         /// for ICollection:
939                         [MonoTODO]
940                         void ICollection.CopyTo(Array dest,int index) 
941                         {
942                                 collection_.CopyTo(dest, index);
943                         }
944                         
945                         [MonoTODO]
946                         public IEnumerator GetEnumerator() 
947                         {
948                                 return collection_.GetEnumerator();
949                         }
950                         
951                         [MonoTODO]
952                         public int IndexOf(object value) 
953                         {
954                                 return collection_.IndexOf(value);
955                         }
956                         
957                         [MonoTODO]
958                         public void Insert(int index,object item) 
959                         {
960                                 //FIXME:                
961                         }
962                         
963                         [MonoTODO]
964                         public void Remove(object value) 
965                         {
966                                 //FIXME:                
967                         }
968                         
969                         [MonoTODO]
970                         public void RemoveAt(int index) 
971                         {
972                                 //FIXME:                
973                         }
974                 }  // --- end of ComboBox.ObjectCollection ---
975         }
976 }