ClientData.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 » ClientData.cs
//-----------------------------------------------------------------------------
// wx.NET - ClientData.cs
//
// The wxClientData wrapper class.
//
// Written by Bryan Bulten (bryan@bulten.ca)
// (C) 2003 Bryan Bulten
// Licensed under the wxWidgets license, see LICENSE.txt for details.
//
// $Id: ClientData.cs,v 1.13 2007/12/25 19:30:23 harald_meyer Exp $
//-----------------------------------------------------------------------------

using System;
using System.Runtime.InteropServices;

namespace wx{
    /** Base class of all classes encapsulating client data.
     * All classes deriving from wx.EvtHandler (such as all controls and App)
     * can hold arbitrary data which is here referred to as "client data". This
     * is useful e.g. for scripting languages which need to handle shadow objects
     * for most of wxWidgets' classes and which store a handle to such a shadow
     * class as client data in that class. This data can either be of type void
     * - in which case the data container does not take care of freeing the data
     * again or it is of type wxClientData or its derivatives. In that case the
     * container (e.g. a control) will free the memory itself later. Note that
     * you must not assign both void data and data derived from the
     * ClientData class to a container.
     *
     * Some controls can hold various items and these controls can additionally
     * hold client data for each item. This is the case for Choice, ComboBox
     * and ListBox. TreeCtrl has a specialized class TreeItemData for each item
     * in the tree.
     * 
     * Refer to SystemObjectClientData for an opportunity to add .NET objects as client
     * as client data.
    */
  public class ClientData : Object
  {
    [DllImport("wx-c")] static extern IntPtr wxClientData_ctor();
    [DllImport("wx-c")] static extern void wxClientData_dtor(IntPtr self);
    [DllImport("wx-c")] static extern void wxClientData_RegisterDisposable(IntPtr self, Virtual_Dispose onDispose);
    
    //---------------------------------------------------------------------
        
    public ClientData(IntPtr wxObject)
      : base(wxObject, StorageMode.RegisteredObject) 
    { 
      this.wxObject = wxObject;
    }
    
    internal ClientData(IntPtr wxObject, bool memOwn)
            : base(wxObject, StorageMode.RegisteredObject)
    { 
      this.memOwn = memOwn;
      this.wxObject = wxObject;
    }

    public ClientData()
      : this(wxClientData_ctor(), true) 
    { 
      virtual_Dispose = new Virtual_Dispose(VirtualDispose);
      wxClientData_RegisterDisposable(wxObject, virtual_Dispose);
    }

    //---------------------------------------------------------------------
        
    public override void Dispose()
    {
      if (!disposed)
      {
                if (wxObject != IntPtr.Zero)
        {
          if (memOwn)
          {
            wxClientData_dtor(wxObject);
            memOwn = false;
          }
        }
        RemoveObject(wxObject);
        wxObject = IntPtr.Zero;
                --validInstancesCount;
                disposed = true;
      }
      base.Dispose();
      GC.SuppressFinalize(this);
    }
    
    //---------------------------------------------------------------------
    
    ~ClientData() 
    {
      Dispose();
    }
  }

    //---------------------------------------------------------------------

    /** Generate an instance of this class to use an System.Object as client data of choices etc.
     * This simply generates an instance of ClientData, which hods a new instance of \c wxClientData.
     * Of course, that \c wxClientData does not hold any data, but when .NET code refers to client data
     * of a Choice or another control, the selector will use this pointer to a \c wxClientData to
     * identify this instance via \c Object.FindObject().
     * */
    public class SystemObjectClientData : ClientData
    {
        object _data;
        public SystemObjectClientData(object data)
            : base()
        {
            this._data=data;
        }

        public object Data { get { return this._data; } }
    }

    //---------------------------------------------------------------------
    
  public class StringClientData : ClientData
  {
    [DllImport("wx-c")] static extern IntPtr wxStringClientData_ctor(IntPtr data);
    [DllImport("wx-c")] static extern void   wxStringClientData_dtor(IntPtr self);
    [DllImport("wx-c")] static extern void   wxStringClientData_SetData(IntPtr self, IntPtr data);
    [DllImport("wx-c")] static extern IntPtr wxStringClientData_GetData(IntPtr self);
    
    //---------------------------------------------------------------------
        
    public StringClientData()
      : this(new wxString("")) { }
      
    public StringClientData(string data)
            : this(new wxString(data))
        {
        }

        public StringClientData(wxString data)
      : this(wxStringClientData_ctor(data.wxObject), true) { }
      
    public StringClientData(IntPtr wxObject)
      : base(wxObject) 
    { 
      this.wxObject = wxObject;
    }
      
    internal StringClientData(IntPtr wxObject, bool memOwn)
      : base(wxObject)
    { 
      this.memOwn = memOwn;
      this.wxObject = wxObject;
    }
    
    //---------------------------------------------------------------------
        
    public override void Dispose()
    {
      if (!disposed)
      {
                if (wxObject != IntPtr.Zero)
        {
          if (memOwn)
          {
            wxStringClientData_dtor(wxObject);
            memOwn = false;
          }
        }
        RemoveObject(wxObject);
        wxObject = IntPtr.Zero;
                --validInstancesCount;
                disposed = true;
      }
      
      base.Dispose();
      GC.SuppressFinalize(this);
    }
    
    //---------------------------------------------------------------------
    
    ~StringClientData() 
    {
      Dispose();
    }

    //---------------------------------------------------------------------
    
    public string Data
    {
      get { return new wxString(wxStringClientData_GetData(wxObject), true); }
      set
            {
                wxString wxValue=new wxString(value);
                wxStringClientData_SetData(this.wxObject, wxValue.wxObject);
            }
    }
  }
}

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