DND.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 » DND.cs
//-----------------------------------------------------------------------------
// wx.NET - Dnd.cs
//
// The wxDND wrapper classes.
//
// Written by Bryan Bulten (bryan@bulten.ca)
// (C) 2003 by Bryan Bulten
// Licensed under the wxWidgets license, see LICENSE.txt for details.
// 
// $Id: DND.cs,v 1.17 2007/07/02 20:52:57 harald_meyer Exp $
//-----------------------------------------------------------------------------

using System;
using System.Runtime.InteropServices;

namespace wx{
  public enum Drag
  {
    wxDrag_CopyOnly    = 0,
    wxDrag_AllowMove   = 1,
    wxDrag_DefaultMove = 3
  }
  
  //---------------------------------------------------------------------

  public enum DragResult
  {
        wxDragError,
        wxDragNone,
        wxDragCopy,
        wxDragMove,
        wxDragLink,
        wxDragCancel
  }
  
  //---------------------------------------------------------------------

  public class DropSource : Object
  {
    private delegate int Virtual_DoDragDrop(int flags);

    private Virtual_DoDragDrop virtual_DoDragDrop;
    
    protected DataObject m_dataObject = null;
    
    [DllImport("wx-c")] static extern IntPtr wxDropSource_Win_ctor(IntPtr win);
    [DllImport("wx-c")] static extern IntPtr wxDropSource_DataObject_ctor(IntPtr dataObject, IntPtr win);
    [DllImport("wx-c")] static extern void wxDropSource_dtor(IntPtr self);
    [DllImport("wx-c")] static extern void wxDropSource_RegisterVirtual(IntPtr self, Virtual_DoDragDrop doDragDrop);
    [DllImport("wx-c")] static extern int wxDropSource_DoDragDrop(IntPtr self, int flags);
    [DllImport("wx-c")] static extern void wxDropSource_SetData(IntPtr self, IntPtr dataObject);
    
    //---------------------------------------------------------------------

    public DropSource(IntPtr wxObject)
      : base(wxObject) 
    {
      this.wxObject = wxObject;
    }    
      
    internal DropSource(IntPtr wxObject, bool memOwn)
      : base(wxObject)
    { 
      this.memOwn = memOwn;
      this.wxObject = wxObject;
    }
    
    public DropSource(Window win)
      : this(wxDropSource_Win_ctor(Object.SafePtr(win)), true) 
    { 
      m_dataObject = null;
      
      virtual_DoDragDrop = new Virtual_DoDragDrop(DoDoDragDrop);

      wxDropSource_RegisterVirtual( wxObject, virtual_DoDragDrop );
    }

    public DropSource(DataObject dataObject, Window win)
      : this(wxDropSource_DataObject_ctor(Object.SafePtr(dataObject), Object.SafePtr(win)), true) 
    {
      m_dataObject = dataObject;

      virtual_DoDragDrop = new Virtual_DoDragDrop(DoDoDragDrop);
      
      wxDropSource_RegisterVirtual( wxObject, virtual_DoDragDrop );
    }
    
    //---------------------------------------------------------------------
        
    public override void Dispose()
    {
      if (!disposed)
      {
                if (wxObject != IntPtr.Zero)
        {
          if (memOwn)
          {
            wxDropSource_dtor(wxObject);
            memOwn = false;
          }
        }
        RemoveObject(wxObject);
        wxObject = IntPtr.Zero;
                --validInstancesCount;
                disposed = true;
      }
      
      base.Dispose();
      GC.SuppressFinalize(this);
    }
    
    //---------------------------------------------------------------------
    
    ~DropSource() 
    {
      Dispose();
    }

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

    public virtual DragResult DoDragDrop(int flags)
    {
      return (DragResult)wxDropSource_DoDragDrop(wxObject, flags);
    }
    
    private int DoDoDragDrop(int flags)
    {
      return (int)DoDragDrop(flags);
    }
    
    //---------------------------------------------------------------------
    
    public DataObject DataObject
    {
      get { return m_dataObject; }
      set { m_dataObject = value; wxDropSource_SetData(wxObject, Object.SafePtr(value)); }
    }
  }
  
  //---------------------------------------------------------------------

  public abstract class DropTarget : Object
  {
    private delegate int Virtual_OnDragOver(int x, int y, int def);
    private delegate bool Virtual_OnDrop(int x, int y);
    private delegate int Virtual_OnData3(int x, int y, int def);
    private delegate bool Virtual_GetData();
    private delegate void Virtual_OnLeave();
    private delegate int Virtual_OnEnter(int x, int y, int def);

    private Virtual_OnDragOver virtual_OnDragOver;
    private Virtual_OnDrop virtual_OnDrop;
    private Virtual_OnData3 virtual_OnData3;
    private Virtual_GetData virtual_GetData;
    private Virtual_OnLeave virtual_OnLeave;
    private Virtual_OnEnter virtual_OnEnter;
    
    //---------------------------------------------------------------------
    
    protected DataObject m_dataObject = null;
    
    //---------------------------------------------------------------------
    
    [DllImport("wx-c")] static extern IntPtr wxDropTarget_ctor(IntPtr dataObject);
    [DllImport("wx-c")] static extern void wxDropTarget_dtor(IntPtr self);
    [DllImport("wx-c")] static extern void wxDropTarget_RegisterVirtual(IntPtr self, Virtual_OnDragOver onDragOver, Virtual_OnDrop onDrop, Virtual_OnData3 onData, Virtual_GetData getData, Virtual_OnLeave onLeave, Virtual_OnEnter onEnter);  
    [DllImport("wx-c")] static extern void   wxDropTarget_RegisterDisposable(IntPtr self, Virtual_Dispose onDispose);
    [DllImport("wx-c")] static extern void   wxDropTarget_SetDataObject(IntPtr self, IntPtr dataObject);
    [DllImport("wx-c")] static extern int wxDropTarget_OnEnter(IntPtr self, int x, int y, int def);
    [DllImport("wx-c")] static extern int wxDropTarget_OnDragOver(IntPtr self, int x, int y, int def);
    [DllImport("wx-c")] static extern void   wxDropTarget_OnLeave(IntPtr self);
    [DllImport("wx-c")] static extern bool wxDropTarget_OnDrop(IntPtr self, int x, int y);
    [DllImport("wx-c")] static extern bool wxDropTarget_GetData(IntPtr self);
    
    //---------------------------------------------------------------------

    public DropTarget()
      : this(null) { }    
    
    public DropTarget(DataObject dataObject)
      : this(wxDropTarget_ctor(Object.SafePtr(dataObject)), true) 
    { 
      m_dataObject = dataObject;

      virtual_OnDragOver = new Virtual_OnDragOver(DoOnDragOver);
      virtual_OnDrop = new Virtual_OnDrop(OnDrop);
      virtual_OnData3 = new Virtual_OnData3(DoOnData);
      virtual_GetData = new Virtual_GetData(GetData);
      virtual_OnLeave = new Virtual_OnLeave(OnLeave);
      virtual_OnEnter = new Virtual_OnEnter(DoOnEnter);
      
      wxDropTarget_RegisterVirtual( wxObject, virtual_OnDragOver,
        virtual_OnDrop,
        virtual_OnData3,
        virtual_GetData,
        virtual_OnLeave,
        virtual_OnEnter);
        
      virtual_Dispose = new Virtual_Dispose(VirtualDispose);
      wxDropTarget_RegisterDisposable(wxObject, virtual_Dispose);
    }

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

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

    public virtual DragResult OnDragOver(int x, int y, DragResult def)
    {
      return (DragResult)wxDropTarget_OnDragOver(wxObject, x, y, (int)def);
    }
    
    private int DoOnDragOver(int x, int y, int def)
    {
      return (int)OnDragOver(x, y, (DragResult)def);
    }
    
    //---------------------------------------------------------------------

    public virtual bool OnDrop(int x, int y)
    {
      return wxDropTarget_OnDrop(wxObject, x, y);
    }
    
    //---------------------------------------------------------------------

    public abstract DragResult OnData(int x, int y, DragResult def);
    
    private int DoOnData(int x, int y, int def)
    {
      return (int)OnData(x, y, (DragResult) def);
    }

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

    public virtual bool GetData()
    {
      return wxDropTarget_GetData(wxObject);
    }
    
    //---------------------------------------------------------------------

    public virtual DragResult OnEnter(int x, int y, DragResult def)
    {
      return (DragResult)wxDropTarget_OnEnter(wxObject, x, y, (int)def);
    }
    
    private int DoOnEnter(int x, int y, int def)
    {
      return (int)OnEnter(x, y, (DragResult) def);
    }
    
    //---------------------------------------------------------------------

    public virtual void OnLeave()
    {
      wxDropTarget_OnLeave(wxObject);
    }
    
    //---------------------------------------------------------------------

    public DataObject DataObject
    {
      get { return m_dataObject; }
      set { m_dataObject = value; wxDropTarget_SetDataObject(wxObject, Object.SafePtr(value)); }
    }
  }
  
  //---------------------------------------------------------------------

  public abstract class TextDropTarget : DropTarget
  {
    [DllImport("wx-c")] static extern bool wxTextDropTarget_OnDrop(IntPtr self, int x, int y);
    [DllImport("wx-c")] static extern bool wxTextDropTarget_GetData(IntPtr self);

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

    public TextDropTarget()
      : base(new TextDataObject()) {}
      
    public abstract bool OnDropText(int x, int y, string text);

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

    public override DragResult OnData(int x, int y, DragResult def)
    {
      if (!GetData())
        return DragResult.wxDragNone;
        
      TextDataObject dobj = (TextDataObject)m_dataObject;
    
      return OnDropText(x, y, dobj.Text) ? def : DragResult.wxDragNone;
    }

    //---------------------------------------------------------------------
        
    public override bool OnDrop(int x, int y)
    {
      return wxTextDropTarget_OnDrop(wxObject, x, y);
    }
    
    //---------------------------------------------------------------------

    public override bool GetData()
    {
      return wxTextDropTarget_GetData(wxObject);
    }
  }
  
  //---------------------------------------------------------------------

  public abstract class FileDropTarget : DropTarget
  {
    [DllImport("wx-c")] static extern bool wxFileDropTarget_OnDrop(IntPtr self, int x, int y);
    [DllImport("wx-c")] static extern bool wxFileDropTarget_GetData(IntPtr self);

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

    public FileDropTarget()
      : base(new FileDataObject()) {}
 
    public abstract bool OnDropFiles(int x, int y, string[] filenames);
    
    //---------------------------------------------------------------------

    public override DragResult OnData(int x, int y, DragResult def)
    {
      if ( !GetData() )
        return DragResult.wxDragNone;
        
      FileDataObject dobj = (FileDataObject)m_dataObject;
      
      return OnDropFiles(x, y, dobj.Filenames) ? def : DragResult.wxDragNone;
    }

    //---------------------------------------------------------------------
                
    public override bool OnDrop(int x, int y)
    {
      return wxFileDropTarget_OnDrop(wxObject, x, y);
    }
    
    //---------------------------------------------------------------------

    public override bool GetData()
    {
      return wxFileDropTarget_GetData(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.