VLBox.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 » VLBox.cs
//-----------------------------------------------------------------------------
// wx.NET - VLBox.cs
//
// The wxVListBox wrapper class.
//
// Written by Alexander Olk (xenomorph2@onlinehome.de)
// (C) 2004 by Alexander Olk
// Licensed under the wxWidgets license, see LICENSE.txt for details.
//
// $Id: VLBox.cs,v 1.7 2007/12/08 23:21:15 harald_meyer Exp $
//-----------------------------------------------------------------------------

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

namespace wx{
  public abstract class VListBox : VScrolledWindow, IEnumerable
  {
    private delegate int Virtual_IntInt(int n);
    private delegate void Virtual_VoidDcRectSizeT(IntPtr dc, IntPtr rect, int n);

    private Virtual_VoidDcRectSizeT onDrawItem;
    private Virtual_IntInt onMeasureItem;
    private Virtual_VoidDcRectSizeT onDrawSeparator;
    private Virtual_VoidDcRectSizeT onDrawBackground;
    private Virtual_IntInt onGetLineHeight;
    
    [DllImport("wx-c")] static extern IntPtr wxVListBox_ctor(IntPtr parent, int id, int posX, int posY, int width, int height, uint style, IntPtr name);
    [DllImport("wx-c")] static extern void wxVListBox_RegisterVirtual(IntPtr self, 
      Virtual_VoidDcRectSizeT onDrawItem, 
      Virtual_IntInt onMeasureItem, 
      Virtual_VoidDcRectSizeT onDrawSeparator,
      Virtual_VoidDcRectSizeT onDrawBackground,
      Virtual_IntInt onGetLineHeight);
    [DllImport("wx-c")][return:MarshalAs(UnmanagedType.U1)] static extern bool wxVListBox_Create(IntPtr self,IntPtr parent, int id, int posX, int posY, int width, int height, uint style, IntPtr name);    
    [DllImport("wx-c")] static extern void wxVListBox_OnDrawSeparator(IntPtr self, IntPtr dc, ref Rectangle rect, int n);
    [DllImport("wx-c")] static extern void wxVListBox_OnDrawBackground(IntPtr self, IntPtr dc, ref Rectangle rect, int n);
    [DllImport("wx-c")] static extern int wxVListBox_OnGetLineHeight(IntPtr self, int line);
    [DllImport("wx-c")] static extern int wxVListBox_GetItemCount(IntPtr self);
    [DllImport("wx-c")] static extern bool wxVListBox_HasMultipleSelection(IntPtr self);
    [DllImport("wx-c")] static extern int wxVListBox_GetSelection(IntPtr self);
    [DllImport("wx-c")] static extern bool wxVListBox_IsCurrent(IntPtr self, int item);
    [DllImport("wx-c")] static extern bool wxVListBox_IsSelected(IntPtr self, int item);
    [DllImport("wx-c")] static extern int wxVListBox_GetSelectedCount(IntPtr self);
    [DllImport("wx-c")] static extern int wxVListBox_GetFirstSelected(IntPtr self, out ulong cookie);
    [DllImport("wx-c")] static extern int wxVListBox_GetNextSelected(IntPtr self, out ulong cookie);
    [DllImport("wx-c")] static extern void wxVListBox_GetMargins(IntPtr self, out Point pt);
    [DllImport("wx-c")] static extern IntPtr wxVListBox_GetSelectionBackground(IntPtr self);
    [DllImport("wx-c")] static extern void wxVListBox_SetItemCount(IntPtr self, int count);
    [DllImport("wx-c")] static extern void wxVListBox_Clear(IntPtr self);
    [DllImport("wx-c")] static extern void wxVListBox_SetSelection(IntPtr self, int selection);
    [DllImport("wx-c")] static extern bool wxVListBox_Select(IntPtr self, int item, bool select);
    [DllImport("wx-c")] static extern bool wxVListBox_SelectRange(IntPtr self, int from, int to);
    [DllImport("wx-c")] static extern void wxVListBox_Toggle(IntPtr self, int item);
    [DllImport("wx-c")] static extern bool wxVListBox_SelectAll(IntPtr self);
    [DllImport("wx-c")] static extern bool wxVListBox_DeselectAll(IntPtr self);
    [DllImport("wx-c")] static extern void wxVListBox_SetMargins(IntPtr self, ref Point pt);
    [DllImport("wx-c")] static extern void wxVListBox_SetMargins2(IntPtr self, int x, int y);
    [DllImport("wx-c")] static extern void wxVListBox_SetSelectionBackground(IntPtr self, IntPtr col);
    
    public VListBox(IntPtr wxObject)
      : base(wxObject) {}
      
    public VListBox()
      : this(null, Window.UniqueID, wxDefaultPosition, wxDefaultSize, 0, "") {}  
      
    public VListBox(Window parent)
      : this(parent, Window.UniqueID, wxDefaultPosition, wxDefaultSize, 0, "") {}
      
    public VListBox(Window parent, int id)
      : this(parent, id, wxDefaultPosition, wxDefaultSize, 0, "") {}
      
    public VListBox(Window parent, int id, Point pos)
      : this(parent, id, pos, wxDefaultSize, 0, "") {}
      
    public VListBox(Window parent, int id, Point pos, Size size)
      : this(parent, id, pos, size, 0, "") {}
      
    public VListBox(Window parent, int id, Point pos, Size size, uint style)
      : this(parent, id, pos, size, style, "") {}

        public VListBox(Window parent, int id, Point pos, Size size, uint style, string name)
            : this(parent, id, pos, size, style, wxString.SafeNew(name))
        {
        }
    public VListBox(Window parent, int id, Point pos, Size size, uint style, wxString name)
      : this(wxVListBox_ctor(Object.SafePtr(parent), id, pos.X, pos.Y, size.Width, size.Height, (uint)style, Object.SafePtr( name)))
    {
      onDrawItem = new Virtual_VoidDcRectSizeT(DoOnDrawItem);
      onMeasureItem = new Virtual_IntInt(OnMeasureItem);
      onDrawSeparator = new Virtual_VoidDcRectSizeT(DoOnDrawSeparator);
      onDrawBackground = new Virtual_VoidDcRectSizeT(DoOnDrawBackground);
      onGetLineHeight = new Virtual_IntInt(OnGetLineHeight);

      wxVListBox_RegisterVirtual(wxObject, 
        onDrawItem,
        onMeasureItem,
        onDrawSeparator,
        onDrawBackground,
        onGetLineHeight);
    }
    
    //---------------------------------------------------------------------
    // ctors with self created id
    
    public VListBox(Window parent, Point pos)
      : this(parent, Window.UniqueID, pos, wxDefaultSize, 0, "") {}
      
    public VListBox(Window parent, Point pos, Size size)
      : this(parent, Window.UniqueID, pos, size, 0, "") {}
      
    public VListBox(Window parent, Point pos, Size size, uint style)
      : this(parent, Window.UniqueID, pos, size, style, "") {}
    
    public VListBox(Window parent, Point pos, Size size, uint style, string name)
      : this(parent, Window.UniqueID, pos, size, style, name) {}
    
    //-----------------------------------------------------------------------------

        public new bool Create(Window parent, int id, Point pos, Size size, uint style, string name)
        {
            return this.Create(parent, id, pos, size, style, wxString.SafeNew(name));
        }
    public new bool Create(Window parent, int id, Point pos, Size size, uint style, wxString name)
    {
      return wxVListBox_Create(wxObject, Object.SafePtr(parent), id, pos.X, pos.Y, size.Width, size.Height, style, Object.SafePtr( name)); 
    }
    
    //-----------------------------------------------------------------------------
    
    protected abstract void OnDrawItem(DC dc, Rectangle rect, int n);
    
    private void DoOnDrawItem(IntPtr dc, IntPtr rect, int n)
    {
      OnDrawItem((DC)FindObject(dc, typeof(DC)), new wxRect(rect), n);
    }
    
    //-----------------------------------------------------------------------------
    
    protected abstract int OnMeasureItem(int n);
    
    //-----------------------------------------------------------------------------
    
    protected virtual void OnDrawSeparator(DC dc, Rectangle rect, int n)
    {
      wxVListBox_OnDrawSeparator(wxObject, Object.SafePtr(dc), ref rect, n);
    }
    
    private void DoOnDrawSeparator(IntPtr dc, IntPtr rect, int n)
    {
      OnDrawSeparator((DC)FindObject(dc, typeof(DC)), new wxRect(rect), n);
    }
    
    //-----------------------------------------------------------------------------
    
    protected virtual void OnDrawBackground(DC dc, Rectangle rect, int n)
    {
      wxVListBox_OnDrawBackground(wxObject, Object.SafePtr(dc), ref rect, n);
    }
    
    private void DoOnDrawBackground(IntPtr dc, IntPtr rect, int n)
    {
      OnDrawBackground((DC)FindObject(dc, typeof(DC)), new wxRect(rect), n);
    }
    
    //-----------------------------------------------------------------------------
    
    protected override int OnGetLineHeight(int line)
    {
      return wxVListBox_OnGetLineHeight(wxObject, line);
    }
    
    //-----------------------------------------------------------------------------
    
    public int ItemCount
    {
      get { return wxVListBox_GetItemCount(wxObject); }
      set { wxVListBox_SetItemCount(wxObject, value); }
    }
    
    //-----------------------------------------------------------------------------
    
    public bool HasMultipleSelection
    {
      get { return wxVListBox_HasMultipleSelection(wxObject); }
    }
    
    //-----------------------------------------------------------------------------
    
    public int Selection
    {
      get { return wxVListBox_GetSelection(wxObject); }
      set
            {
                wxVListBox_SetSelection(wxObject, value);
            }
    }
    
    //-----------------------------------------------------------------------------
    
    public bool IsCurrent(int item)
    {
      return wxVListBox_IsCurrent(wxObject, item);
    }
    
    //-----------------------------------------------------------------------------
    
    public bool IsSelected(int item)
    {
      return wxVListBox_IsSelected(wxObject, item);
    }
    
    //-----------------------------------------------------------------------------
    
    public int SelectedCount
    {
      get { return wxVListBox_GetSelectedCount(wxObject); }
    }
    
    //-----------------------------------------------------------------------------
    
    public int GetFirstSelected(out ulong cookie)
    {
      return wxVListBox_GetFirstSelected(wxObject, out cookie);
    }
    
    //-----------------------------------------------------------------------------
    
    public int GetNextSelected(out ulong cookie)
    {
      return wxVListBox_GetNextSelected(wxObject, out cookie);
    }
    
    //-----------------------------------------------------------------------------
    
    public Point Margins
    {
      get { 
        Point pt = new Point();
        wxVListBox_GetMargins(wxObject, out pt);
        return pt;
      }
      
      set { wxVListBox_SetMargins(wxObject, ref value); }
    }
    
    public void SetMargins(int x, int y)
    {
      wxVListBox_SetMargins2(wxObject, x, y);
    }
    
    //-----------------------------------------------------------------------------
    
    public Colour SelectionBackground
    {
      get { return new Colour(wxVListBox_GetSelectionBackground(wxObject), true); }
      set { wxVListBox_SetSelectionBackground(wxObject, Object.SafePtr(value)); }
    }
    
    //-----------------------------------------------------------------------------
    
    public void Clear()
    {
      wxVListBox_Clear(wxObject);
    }
    
    //-----------------------------------------------------------------------------
    
    public bool Select(int item)
    {
      return Select(item, true);
    }
    
    public bool Select(int item, bool select)
    {
      return wxVListBox_Select(wxObject, item, select);
    }
    
    //-----------------------------------------------------------------------------
    
    public bool SelectRange(int from, int to)
    {
      return wxVListBox_SelectRange(wxObject, from, to);
    }
    
    //-----------------------------------------------------------------------------
    
    public void Toggle(int item)
    {
      wxVListBox_Toggle(wxObject, item);
    }
    
    //-----------------------------------------------------------------------------
    
    public bool SelectAll()
    {
      return wxVListBox_SelectAll(wxObject);
    }
    
    //-----------------------------------------------------------------------------
    
    public bool DeselectAll()
    {
      return wxVListBox_DeselectAll(wxObject);
    }


        /** This will enumerate all selections in the argument list passed to the constructor.
         * This is more convenient and comprehensable than using the original calls to
         * GetFirstSelected()/GetNextSelected().
         */
        public class EnumerateSelections : IEnumerator
        {
            ulong _cookie;
            VListBox _lb;
            int _current;
            public EnumerateSelections(VListBox lb)
            {
                this._lb = lb;
                this._current = -1;
                this._cookie = 0;
            }

            /** To whom it may concern.
             * This is the cookie used for reading the selections. Nothing users need to know.
             */
            public ulong Cookie { get { return this._cookie; } }

            #region IEnumerator Member
            public object Current
            {
                get { return this._current; }
            }

            public bool MoveNext()
            {
                if (this._current < 0)
                    this._current = this._lb.GetFirstSelected(out this._cookie);
                else
                    this._current = this._lb.GetNextSelected(out this._cookie);
                return this._current >= 0;
            }

            public void Reset()
            {
                this._current = this._lb.GetFirstSelected(out this._cookie);
            }
            #endregion
        }



        #region IEnumerable Member
        /** This returns a new instance of EnumerateSelections on this list box.
         */
        public IEnumerator GetEnumerator()
        {
            return new EnumerateSelections(this);
        }

        #endregion
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.