ControlWithItems.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 » ControlWithItems.cs
//-----------------------------------------------------------------------------
// wx.NET - ControlWithItems.cs
//
// The ControlWithItems wrapper class.
//
// Written by Harald Meyer auf'm Hofe
// (C) 2007 Harald Meyer auf'm Hofe
// Licensed under the wxWidgets license, see LICENSE.txt for details.
//
// $Id: ControlWithItems.cs,v 1.3 2007/10/21 15:57:35 harald_meyer Exp $
//-----------------------------------------------------------------------------

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

namespace wx{
    public class ControlWithItems : Control
    {
        #region CAPI
        [DllImport("wx-c")]
        static extern void wxControlWithItems_SetSelection(IntPtr self, int n);
        [DllImport("wx-c")]
        static extern IntPtr wxControlWithItems_GetStringSelection(IntPtr self);
        [DllImport("wx-c")]
        [return: MarshalAs(UnmanagedType.U1)]
        static extern bool wxControlWithItems_SetStringSelection(IntPtr self, IntPtr value);


        [DllImport("wx-c")]
        static extern int wxControlWithItems_FindString(IntPtr self, IntPtr str);

        [DllImport("wx-c")]
        static extern void wxControlWithItems_Delete(IntPtr self, int n);
        [DllImport("wx-c")]
        static extern void wxControlWithItems_Clear(IntPtr self);

        [DllImport("wx-c")]
        static extern int wxControlWithItems_Append(IntPtr self, IntPtr item);
        [DllImport("wx-c")]
        static extern int wxControlWithItems_AppendWithData(IntPtr self, IntPtr item, IntPtr data);

        [DllImport("wx-c")]
        static extern int wxControlWithItems_GetCount(IntPtr self);
        [DllImport("wx-c")]
        static extern IntPtr wxControlWithItems_GetString(IntPtr self, int n);
        [DllImport("wx-c")]
        static extern int wxControlWithItems_GetSelection(IntPtr self);

        [DllImport("wx-c")]
        static extern int wxControlWithItems_Insert(IntPtr self, IntPtr item, int pos);
        [DllImport("wx-c")]
        static extern int wxControlWithItems_InsertWithData(IntPtr self, IntPtr item, int pos, IntPtr data);

        [DllImport("wx-c")]
        static extern IntPtr wxControlWithItems_GetStrings(IntPtr self);

        [DllImport("wx-c")]
        static extern IntPtr wxControlWithItems_GetClientObject(IntPtr self, int n);
        [DllImport("wx-c")]
        static extern void wxControlWithItems_SetClientObject(IntPtr self, int n, IntPtr data);
        [DllImport("wx-c")]
        [return: MarshalAs(UnmanagedType.U1)]
        static extern bool wxControlWithItems_HasClientObjectData(IntPtr self, int n);

        [DllImport("wx-c")]
        static extern void wxControlWithItems_SetString(IntPtr self, int n, IntPtr text);

        [DllImport("wx-c")]
        static extern void wxControlWithItems_Select(IntPtr self, int n);

        [DllImport("wx-c")] [return: MarshalAs(UnmanagedType.U1)]
        static extern bool wxControlWithItems_ShouldInheritColours(IntPtr self);

        [DllImport("wx-c")] [return: MarshalAs(UnmanagedType.U1)]
        static extern bool wxControlWithItems_IsEmpty(IntPtr self);
        #endregion

        #region CTor
        public ControlWithItems(IntPtr wxObject) 
      : base(wxObject) { }
        #endregion

        #region Public Properties
    public int Selection
    {
            get
            {
                if (this.IsEmpty)
                    return -1;
                return wxControlWithItems_GetSelection(this.wxObject);
            }
            set
            {
                wxControlWithItems_SetSelection(this.wxObject, value);
            }
    }

        /** Also refer to method SetStringSelection() that returns a Boolean that is true on success and false otherwise.
         * */
        public string StringSelection
        {
            get
            {
                if (this.IsEmpty)
                    return "";
                return new wxString(wxControlWithItems_GetStringSelection(wxObject), true);
            }
            set
            {
                wxString wxValue = new wxString(value);
                wxControlWithItems_SetStringSelection(wxObject, wxValue.wxObject);
            }
        }

        /** Returns the number of items.
         * */
        public int Count { get { return wxControlWithItems_GetCount(this.wxObject); } }

        /** True iff this is empty.
         * */
        public bool IsEmpty { get { return wxControlWithItems_IsEmpty(this.wxObject); } }

        /** All the currently known labels.
         * Read only property. Alternatively, use the indexer of this class.
         * */
        public string[] Strings
        {
            get
            {
                string[] result = new string[this.Count];
                for (int i = 0; i < result.Length; ++i)
                    result[i] = this.GetString(i);
                return result;
            }
        }

        /** This is equivalent to the methods GetString() and SetString().
         * */
        public string this[int n]
        {
            get { return this.GetString(n); }
            set { this.SetString(n, value); }
        }
        #endregion

        #region Public Methods
        /** Set the label of the entry of index \c n.
         * Refer also to the indexer of this class.
         * */
        public void SetString(int n, string label)
        {
            wxString wxLabel = new wxString(label);
            wxControlWithItems_SetString(this.wxObject, n, wxLabel.wxObject);
        }
        /** Get the label of the entry of index \c n.
         * Refer also to the indexer of this class.
         * */
        public string GetString(int n)
        {
            return new wxString(wxControlWithItems_GetString(this.wxObject, n));
        }

        /**Finds an item whose label matches the given string.
         * \return The zero-based position of the item, or -1 if the string was not found.
         */
        public int FindString(string str)
        {
            return this.FindString(new wxString(str));
        }
        public int FindString(wxString str)
        {
            return wxControlWithItems_FindString(wxObject, str.wxObject);
        }

        /** Select the designated label. Return \c true on success and \c false otherwise.
         * Refer also to property \c StringSelection().
         * */
        public bool SetStringSelection(string selectedLabel)
        {
            wxString wxLabel=new wxString(selectedLabel);
            return wxControlWithItems_SetStringSelection(this.wxObject, wxLabel.wxObject);
        }

        /** \name Client data of items
         * The .NET interface does not distinguish between client data and client object:
         * The interface only supports client objects. Refer  to class SystemObjectClientData.
         */ 
        //@{
        /** Reads client data for item \c n.
         * */
        public ClientData GetClientObject(int n)
        {
            ClientData result = (ClientData)Object.FindObject(wxControlWithItems_GetClientObject(this.wxObject, n), typeof(ClientData));
            // this might seem surplus but in case changes to client data committed within the wx-c dll, this will
            // ensure an update of the client data list at least on reading the changed item.
            return result;
        }

        public void SetClientData(int n, ClientData data)
        {
            data.memOwn = false;
            wxControlWithItems_SetClientObject(this.wxObject, n, data.wxObject);
        }

        public bool HasClientObjectData(int n)
        {
            return wxControlWithItems_HasClientObjectData(this.wxObject, n);
        }
        //@}

        /** \name Maintaining items.
         * */
        //@{
        public void Append(string[] items)
        {
            foreach(string item in items)
                this.Append(item);
        }
        public int Append(string item)
        {
            return this.Append(item, null);
        }
        public int Append(wxString item, ClientData clientData)
        {
            if (clientData == null)
                return wxControlWithItems_Append(this.wxObject, item.wxObject);
            else
            {
                int result=wxControlWithItems_AppendWithData(this.wxObject, item.wxObject, clientData.wxObject);
                return result;
            }
        }
        /** This will append \c item to the end of the item list and associate it with the provided client data.
         * The client data may be \c null. 
         * \result The index of the new item.
         * */
        public int Append(string item, ClientData clientData)
        {
            return this.Append(new wxString(item), clientData);
        }

        public int Insert(string item, int pos)
        {
            return this.Insert(item, pos, null);
        }
        public int Insert(wxString item, int pos, ClientData clientData)
        {
            if (clientData == null)
                return wxControlWithItems_Insert(this.wxObject, item.wxObject, pos);
            else
            {
                int result = wxControlWithItems_InsertWithData(this.wxObject, item.wxObject, pos, clientData.wxObject);
                return result;
            }
        }

        /** Inserts the item into the list before pos, associating the given, typed or untyped, client data pointer with the item.
         * Not valid for ListBox.wxLB_SORT or ComboBox.wxCB_SORT styles, use Append() instead.
         * \result The return value is the index of the newly inserted item. If the insertion failed for some reason, -1 is returned.
        */
        public int Insert(string item, int pos, ClientData clientData)
        {
            return this.Insert(new wxString(item), pos, clientData);
        }

        /** Deletes all items.
         * */
        public void Clear()
        {
            wxControlWithItems_Clear(this.wxObject);
        }

        public void Delete(int n)
        {
            wxControlWithItems_Delete(this.wxObject, n);
        }
        //@}

        public override bool ShouldInheritColours()
        {
            return wxControlWithItems_ShouldInheritColours(this.wxObject);
        }
        #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.