DataObject.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 » DataObject.cs
//-----------------------------------------------------------------------------
// wx.NET - Dataobj.cs
//
// The wxDataObject wrapper class.
//
// Written by Bryan Bulten (bryan@bulten.ca)
// (C) 2003 by Bryan Bulten
// Licensed under the wxWidgets license, see LICENSE.txt for details.
//
// $Id: DataObject.cs,v 1.10 2007/11/11 14:14:46 harald_meyer Exp $
//-----------------------------------------------------------------------------

using System;
using System.Runtime.InteropServices;

namespace wx{
  public abstract class DataObject : Object
  {
    public enum DataDirection
    {
      Get = 0x01,
      Set = 0x02,
      Both = 0x03
    }
    
    //---------------------------------------------------------------------

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

  public class DataObjectSimple : DataObject
  {
    [DllImport("wx-c")] static extern IntPtr wxDataObjectSimple_ctor(IntPtr format);
    [DllImport("wx-c")] static extern void wxDataObjectSimple_dtor(IntPtr self);
    [DllImport("wx-c")] static extern void wxDataObjectSimple_SetFormat(IntPtr self, IntPtr format);
    [DllImport("wx-c")] static extern uint wxDataObjectSimple_GetDataSize(IntPtr self);
    [DllImport("wx-c")] static extern bool wxDataObjectSimple_GetDataHere(IntPtr self, IntPtr buf);
    [DllImport("wx-c")] static extern bool wxDataObjectSimple_SetData(IntPtr self, uint len, IntPtr buf);
    
    //---------------------------------------------------------------------

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

  public class TextDataObject : DataObjectSimple
  {
    [DllImport("wx-c")] static extern IntPtr wxTextDataObject_ctor(IntPtr text);
    [DllImport("wx-c")] static extern void wxTextDataObject_dtor(IntPtr self);
    [DllImport("wx-c")] static extern void wxTextDataObject_RegisterDisposable(IntPtr self, Virtual_Dispose onDispose);
    [DllImport("wx-c")] static extern int wxTextDataObject_GetTextLength(IntPtr self);
    [DllImport("wx-c")] static extern IntPtr wxTextDataObject_GetText(IntPtr self);
    [DllImport("wx-c")] static extern void wxTextDataObject_SetText(IntPtr self, IntPtr text);
    
    //---------------------------------------------------------------------

    public TextDataObject(IntPtr wxObject)
      : base(wxObject) 
    {
      this.wxObject = wxObject;
    }
      
    internal TextDataObject(IntPtr wxObject, bool memOwn)
      : base(wxObject)
    { 
      this.memOwn = memOwn;
      this.wxObject = wxObject;
    }

    public TextDataObject()
      : this("") {}

        public TextDataObject(string text)
            : this(wxString.SafeNew(text))
        {
        }
    public TextDataObject(wxString text)
      : this(wxTextDataObject_ctor(Object.SafePtr(text)), true) 
    {
      virtual_Dispose = new Virtual_Dispose(VirtualDispose);
      wxTextDataObject_RegisterDisposable(wxObject, virtual_Dispose);
    }
      
    //---------------------------------------------------------------------
        
    public override void Dispose()
    {
      if (!disposed)
      {
                if (wxObject != IntPtr.Zero)
        {
          if (memOwn)
          {
            wxTextDataObject_dtor(wxObject);
            memOwn = false;
          }
        }
        RemoveObject(wxObject);
        wxObject = IntPtr.Zero;
                --validInstancesCount;
                disposed = true;
      }
      
      base.Dispose();
      GC.SuppressFinalize(this);
    }
    
    //---------------------------------------------------------------------
    
    ~TextDataObject() 
    {
      Dispose();
    }
      
    //---------------------------------------------------------------------

    public int TextLength
    {
      get { return wxTextDataObject_GetTextLength(wxObject); }
    }
    
    //---------------------------------------------------------------------

    public string Text
    {
      get { return new wxString(wxTextDataObject_GetText(wxObject), true); }
      set
            {
                wxString wxValue = wxString.SafeNew(value);
                wxTextDataObject_SetText(wxObject, Object.SafePtr(wxValue));
            }
    }
  }
  
  //---------------------------------------------------------------------

  public class FileDataObject : DataObjectSimple
  {
    [DllImport("wx-c")] static extern IntPtr wxFileDataObject_ctor();
    [DllImport("wx-c")] static extern void wxFileDataObject_dtor(IntPtr self);
    [DllImport("wx-c")] static extern void wxFileDataObject_RegisterDisposable(IntPtr self, Virtual_Dispose onDispose);
    [DllImport("wx-c")] static extern void wxFileDataObject_AddFile(IntPtr self, IntPtr filename);
    [DllImport("wx-c")] static extern IntPtr wxFileDataObject_GetFilenames(IntPtr self);
    
    //---------------------------------------------------------------------
    
    public FileDataObject(IntPtr wxObject)
      : base(wxObject) 
    {
      this.wxObject = wxObject;
    }
      
    internal FileDataObject(IntPtr wxObject, bool memOwn)
      : base(wxObject)
    { 
      this.memOwn = memOwn;
      this.wxObject = wxObject;
    }
      
    public FileDataObject()
      : this(wxFileDataObject_ctor(), true) 
    {
      virtual_Dispose = new Virtual_Dispose(VirtualDispose);
      wxFileDataObject_RegisterDisposable(wxObject, virtual_Dispose);
    }
    
    //---------------------------------------------------------------------
        
    public override void Dispose()
    {
      if (!disposed)
      {
                if (wxObject != IntPtr.Zero)
        {
          if (memOwn)
          {
            wxFileDataObject_dtor(wxObject);
            memOwn = false;
          }
        }
        RemoveObject(wxObject);
        wxObject = IntPtr.Zero;
                --validInstancesCount;
                disposed = true;
      }
      
      base.Dispose();
      GC.SuppressFinalize(this);
    }
    
    //---------------------------------------------------------------------
    
    ~FileDataObject() 
    {
      Dispose();
    }
      
    //---------------------------------------------------------------------
      
    public void AddFile(string filename)
    {
            wxString wxFilename = wxString.SafeNew(filename);
      wxFileDataObject_AddFile(wxObject, Object.SafePtr(wxFilename));
    }
    
    public string[] Filenames
    {
      get { return new ArrayString(wxFileDataObject_GetFilenames(wxObject), true); }
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.