ListBox.cs :  » GUI » wx-NET » wx » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » wx NET 
wx NET » wx » ListBox.cs
//-----------------------------------------------------------------------------
// wx.NET - ListBox.cs
//
// wxListBox wrapper class.
//
// Written by Bryan Bulten (bryan@bulten.ca)
// (C) 2003 Bryan Bulten
// Licensed under the wxWidgets license, see LICENSE.txt for details.
//
// $Id: ListBox.cs,v 1.31 2007/11/11 14:14:46 harald_meyer Exp $
//-----------------------------------------------------------------------------

using System;
using System.Drawing;
using System.Runtime.InteropServices;

namespace wx{
  public class ListBox : ControlWithItems
  {
    public const uint wxLB_SORT             = 0x0010;
    public const uint wxLB_SINGLE           = 0x0020;
    public const uint wxLB_MULTIPLE         = 0x0040;
    public const uint wxLB_EXTENDED         = 0x0080;
    public const uint wxLB_OWNERDRAW        = 0x0100;
    public const uint wxLB_NEED_SB          = 0x0200;
    public const uint wxLB_ALWAYS_SB        = 0x0400;
    public const uint wxLB_HSCROLL          = wxHSCROLL;
    public const uint wxLB_INT_HEIGHT       = 0x0800;
  
    //---------------------------------------------------------------------
  
    [DllImport("wx-c")] static extern IntPtr wxListBox_ctor();
    [DllImport("wx-c")] static extern void   wxListBox_dtor(IntPtr self);
    [DllImport("wx-c")] static extern bool   wxListBox_Create(IntPtr self, IntPtr parent, int id, ref Point pos, ref Size size, IntPtr choices, uint style, IntPtr validator, IntPtr name);
    [DllImport("wx-c")] static extern void   wxListBox_InsertItems(IntPtr self, IntPtr items, int pos);
    [DllImport("wx-c")] static extern void   wxListBox_Set(IntPtr self, IntPtr items, IntPtr[] clientData);
    [DllImport("wx-c")] static extern void   wxListBox_Select(IntPtr self, int n);
    [DllImport("wx-c")] static extern void   wxListBox_Deselect(IntPtr self, int n);
    [DllImport("wx-c")] static extern void   wxListBox_DeselectAll(IntPtr self, int itemToLeaveSelected);
    [DllImport("wx-c")] static extern IntPtr wxListBox_GetSelections(IntPtr self);
    [DllImport("wx-c")] static extern void   wxListBox_SetFirstItem(IntPtr self, int n);
    [DllImport("wx-c")] static extern void   wxListBox_SetFirstItemText(IntPtr self, IntPtr s);
    [DllImport("wx-c")] static extern bool   wxListBox_HasMultipleSelection(IntPtr self);
    [DllImport("wx-c")] static extern bool   wxListBox_IsSorted(IntPtr self);
    [DllImport("wx-c")] static extern void   wxListBox_Command(IntPtr self, IntPtr evt);
  
    //---------------------------------------------------------------------
    
    public ListBox(IntPtr wxObject) 
      : base(wxObject) { }
  
    public ListBox()
      : base(wxListBox_ctor()) { }

    public ListBox(Window parent, int id)
      : this(parent, id, wxDefaultPosition, wxDefaultSize, null, 0, null, null) { }
  
    public ListBox(Window parent, int id, Point pos)
      : this(parent, id, pos, wxDefaultSize, null, 0, null, null) { }
  
    public ListBox(Window parent, int id, Point pos, Size size)
      : this(parent, id, pos, size, null, 0, null, null) { }
  
    public ListBox(Window parent, int id, Point pos, Size size, string[] choices)
      : this(parent, id, pos, size, choices, 0, null, null) { }
  
    public ListBox(Window parent, int id, Point pos, Size size, string[] choices, uint style)
      : this(parent, id, pos, size, choices, style, null, null) { }
  
    public ListBox(Window parent, int id, Point pos, Size size, string[] choices, uint style, Validator val)
      : this(parent, id, pos, size, choices, style, val, null) { }

        public ListBox(Window parent, int id, Point pos, Size size, string[] choices, uint style, Validator validator, string name)
            : this(parent, id, pos, size, ArrayString.SafeNewFrom(choices), style, validator, new wxString(name))
        {
        }
        internal ListBox(Window parent, int id, Point pos, Size size, ArrayString choices, uint style, Validator validator, wxString name)
      : base(wxListBox_ctor())
    {
      if(!wxListBox_Create(wxObject, Object.SafePtr(parent), id,
          ref pos, ref size, Object.SafePtr(choices), style,
          Object.SafePtr(validator), Object.SafePtr(name)))
      {
        throw new InvalidOperationException("Failed to create ListBox");
      }
    }
    
    //---------------------------------------------------------------------
    // ctors with self created id
    
    public ListBox(Window parent)
      : this(parent, Window.UniqueID, wxDefaultPosition, wxDefaultSize, null, 0, null, null) { }
  
    public ListBox(Window parent, Point pos)
      : this(parent, Window.UniqueID, pos, wxDefaultSize, null, 0, null, null) { }
  
    public ListBox(Window parent, Point pos, Size size)
      : this(parent, Window.UniqueID, pos, size, null, 0, null, null) { }
  
    public ListBox(Window parent, Point pos, Size size, string[] choices)
      : this(parent, Window.UniqueID, pos, size, choices, 0, null, null) { }
  
    public ListBox(Window parent, Point pos, Size size, string[] choices, uint style)
      : this(parent, Window.UniqueID, pos, size, choices, style, null, null) { }
  
    public ListBox(Window parent, Point pos, Size size, string[] choices, uint style, Validator val)
      : this(parent, Window.UniqueID, pos, size, choices, style, val, null) { }
  
    public ListBox(Window parent, Point pos, Size size, string[] choices, uint style, Validator validator, string name)
            : this(parent, Window.UniqueID, pos, size, ArrayString.SafeNewFrom(choices), style, validator, new wxString(name))
        {
        }
        internal ListBox(Window parent, Point pos, Size size, ArrayString choices, uint style, Validator validator, wxString name)
      : this( parent, Window.UniqueID, pos, size, choices, style, validator, name)
        {
        }
    
    //---------------------------------------------------------------------

        public bool Create(Window parent, int id, Point pos, Size size,
                string[] choices, uint style, Validator validator, string name)
        {
            return this.Create(parent, id, pos, size, ArrayString.SafeNewFrom(choices), style, validator, new wxString(name));
        }
        internal bool Create(Window parent, int id, Point pos, Size size,
        ArrayString choices, uint style, Validator validator, wxString name)
    {
      return wxListBox_Create(wxObject, Object.SafePtr(parent), id,
                ref pos, ref size, Object.SafePtr(choices), style,
          Object.SafePtr(validator), Object.SafePtr(name));
    }
      
    //---------------------------------------------------------------------
      
    public void InsertItems(string[] items, int pos)
    {
        this.InsertItems(ArrayString.SafeNewFrom(items), pos);
    }
        internal void InsertItems(ArrayString items, int pos)
        {
            wxListBox_InsertItems(wxObject, Object.SafePtr(items), pos);
        }
  
    //---------------------------------------------------------------------

        public void Set(string[] items, ClientData[] data)
        {
            this.Set(new ArrayString(items), data);
        }

        internal void Set(ArrayString items, ClientData[] data)
    {
            if (items.Count != data.Length)
                throw new ArgumentOutOfRangeException("data");
            IntPtr[] clientobjects = new IntPtr[data.Length];
            for (int i = 0; i < data.Length; ++i)
            {
                clientobjects[i] = data[i].wxObject;
            }
            wxListBox_Set(wxObject, Object.SafePtr(items), clientobjects);
    }

        public void Set(string[] items)
        {
            this.Set(new ArrayString(items));
        }
        internal void Set(ArrayString items)
    {
      wxListBox_Set(this.wxObject, Object.SafePtr(items), null);
    }
  
    //---------------------------------------------------------------------
    
    public bool Sorted
    {
      get { return wxListBox_IsSorted(wxObject); }
    }
  
    //---------------------------------------------------------------------
  
    public bool HasMultipleSelection()
    {
      return wxListBox_HasMultipleSelection(wxObject);
    }
  
    //---------------------------------------------------------------------
  
    public void Deselect(int n)
    {
      wxListBox_Deselect(wxObject, n);
    }
  
    public void DeselectAll(int itemToLeaveSelected)
    {
      wxListBox_DeselectAll(wxObject, itemToLeaveSelected);
    }
  
    //---------------------------------------------------------------------
  
    public int[] Selections
    {
      get { return new ArrayInt(wxListBox_GetSelections(wxObject), true); }
    }
  
    //---------------------------------------------------------------------
  
    public void SetFirstItem(int n)
    {
      wxListBox_SetFirstItem(wxObject, n);
    }
  
    public void SetFirstItem(string s)
    {
            this.SetFirstItem(new wxString(s));
        }
        public void SetFirstItem(wxString s)
        {
      wxListBox_SetFirstItemText(this.wxObject, s.wxObject);
    }
  
    //---------------------------------------------------------------------
  
    public void Command(Event evt)
    {
      wxListBox_Command(wxObject, Object.SafePtr(evt));
    }
  
    //---------------------------------------------------------------------
    
    public event EventListener Select
    {
      add { AddCommandListener(Event.wxEVT_COMMAND_LISTBOX_SELECTED, ID, value, this); }
      remove { RemoveHandler(value, this); }
    }
  
    public event EventListener DoubleClick
    {
      add { AddCommandListener(Event.wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, ID, value, this); }
      remove { RemoveHandler(value, this); }
    }
  }
  
  //---------------------------------------------------------------------
  
  public class CheckListBox : ListBox
  {
    [DllImport("wx-c")] static extern IntPtr wxCheckListBox_ctor1();
    [DllImport("wx-c")] static extern IntPtr wxCheckListBox_ctor2(IntPtr parent, 
      int id,
      ref Point pos,
      ref Size size,
      IntPtr choices,
      uint style,
      IntPtr validator,
      IntPtr name);
    [DllImport("wx-c")] static extern bool wxCheckListBox_IsChecked(IntPtr self, int index);
    [DllImport("wx-c")] static extern void wxCheckListBox_Check(IntPtr self, int index, bool check);
    [DllImport("wx-c")] static extern int wxCheckListBox_GetItemHeight(IntPtr self);
    
    //---------------------------------------------------------------------
  
    public CheckListBox(IntPtr wxObject)
      : base(wxObject) {}
      
    public CheckListBox()
      : base(wxCheckListBox_ctor1()) {}
      
    public CheckListBox(Window parent, int id)
      : this(parent, id, wxDefaultPosition, wxDefaultSize, (string[])null, 0, null, "") {}
      
    public CheckListBox(Window parent, int id, Point pos)
      : this(parent, id, pos, wxDefaultSize, (string[])null, 0, null, "") {}
      
    public CheckListBox(Window parent, int id, Point pos, Size size)
      : this(parent, id, pos, size, (string[])null, 0, null, "") {}
      
    public CheckListBox(Window parent, int id, Point pos, Size size, string[] choices)
      : this(parent, id, pos, size, choices, 0, null, "") {}
      
    public CheckListBox(Window parent, int id, Point pos, Size size, string[] choices, uint style)
      : this(parent, id, pos, size, choices, style, null, "") {}
      
    public CheckListBox(Window parent, int id, Point pos, Size size, string[] choices, uint style, Validator validator)
      : this(parent, id, pos, size, choices, style, validator, "") {}
      
    public CheckListBox(Window parent, int id, Point pos, Size size, string[] choices, uint style, Validator validator, string name)
      : this(parent, id, pos, size, ArrayString.SafeNewFrom(choices), style, validator, new wxString(name))
        {
        }
        internal CheckListBox(Window parent, int id, Point pos, Size size, ArrayString choices, uint style, Validator validator, wxString name)
      : base(wxCheckListBox_ctor2(Object.SafePtr(parent), id, ref pos, ref size, Object.SafePtr(choices), style, Object.SafePtr(validator), name.wxObject))
        {
        }
      
    //---------------------------------------------------------------------
    // ctors with self created id
      
    public CheckListBox(Window parent)
            : this(parent, Window.UniqueID, wxDefaultPosition, wxDefaultSize, null, 0, null, new wxString("")) { }
      
    public CheckListBox(Window parent, Point pos)
            : this(parent, Window.UniqueID, pos, wxDefaultSize, null, 0, null, new wxString("")) { }
      
    public CheckListBox(Window parent, Point pos, Size size)
      : this(parent, Window.UniqueID, pos, size, null, 0, null, new wxString("")) {}
      
    public CheckListBox(Window parent, Point pos, Size size, string[] choices)
      : this(parent, Window.UniqueID, pos, size, choices, 0, null, "") {}
      
    public CheckListBox(Window parent, Point pos, Size size, string[] choices, uint style)
      : this(parent, Window.UniqueID, pos, size, choices, style, null, "") {}
      
    public CheckListBox(Window parent, Point pos, Size size, string[] choices, uint style, Validator validator)
      : this(parent, Window.UniqueID, pos, size, choices, style, validator, "") {}
      
    public CheckListBox(Window parent, Point pos, Size size, string[] choices, uint style, Validator validator, string name)
      : this(parent, Window.UniqueID, pos, size, choices, style, validator, name) {}
      
    //--------------------------------------------------------------------
    
    public bool IsChecked(int index)
    {
      return wxCheckListBox_IsChecked(wxObject, index);
    }
    
    //---------------------------------------------------------------------
    
    public void Check(int index)
    {
      Check(index, true);
    }
    
    public void Check(int index, bool check)
    {
      wxCheckListBox_Check(wxObject, index, check);
    }
    
    //---------------------------------------------------------------------
    
    #if ! __WXMAC__
    public int ItemHeight
    {
      get { return wxCheckListBox_GetItemHeight(wxObject); }
    }
    #endif
    
    //---------------------------------------------------------------------
    
    public event EventListener Checked
    {
      add { AddCommandListener(Event.wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, ID, value, this); }
      remove { RemoveHandler(value, this); }
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.