/*

CLASS {NATIVE_Clipboard|_CSharp}, NATIVE:

*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

using AL4;

public class AL4_clipboard
{

    public static string Get_text_from_clipboard()
    {
       string s = "";
    	try
    	{
       		s = Clipboard.GetText();
    	}
    	catch(Exception) {}
       return s;
    }

    public static void Set_text_to_clipboard(string Text)
    {
    	try
    	{
	       if (Text == "") Clipboard.Clear();
	       else Clipboard.SetText(Text);
    	}
    	catch(Exception) {}
    }
    
    public static bool Is_text_in_clipboard()
    {
    	try
    	{
    	return Clipboard.ContainsText();
    	}
    	catch(Exception)
    	{
    		return false;
    	}
    }

    public static byte Get_files_from_clipboard(ArrayStr Paths)
    {
		Paths.Clear();
    	try
    	{
    		if (Clipboard.ContainsFileDropList())
    		{
    			var returnList = Clipboard.GetFileDropList();
    			for (int i = 0; i < returnList.Count; i ++)
    			{
    				Paths.Add(returnList[i]);
    			}
    			if (Paths.Count == 0) return 0;
    			var d_check = Clipboard.GetData("Preferred DropEffect");
    			if (d_check != null && d_check is MemoryStream)
    			{
    				byte[] d_effect = new byte[4];
    				((MemoryStream)d_check).Read(d_effect, 0, d_effect.Length);
    				if (d_effect[0] == 2) return 1;
    			}
    		} 
    	}
    	catch(Exception) {}
    	return 0;
    }

    public static void Files_to_clipboard(ArrayStr Paths, byte Op)
    {
    	System.Collections.Specialized.StringCollection paths 
    		= new System.Collections.Specialized.StringCollection(); 
    	try
    	{
    		for (int i = 0; i < Paths.Count; i++)
    			paths.Add(Paths.get_str(i));
    		
	    	byte[] moveEffect = new byte[] {2, 0, 0, 0};
	    	if (Op == 0) moveEffect[0] = 5;
	    	
			MemoryStream dropEffect = new MemoryStream();
			dropEffect.Write(moveEffect, 0, moveEffect.Length);
			
			DataObject data = new DataObject();
			data.SetFileDropList(paths);
			data.SetData("Preferred DropEffect", dropEffect);
			
			Clipboard.Clear();
			Clipboard.SetDataObject(data, true);
    	}
    	catch(Exception) {}
    }

    public static bool Clipboard_has_files()
    {
    	try
    	{
    		return Clipboard.ContainsFileDropList();
    	}
    	catch(Exception) 
    	{
    		return false;
    	}
    }


    
    /*
    
CONST STR:
    NATIVE_Import_clipboard = ""

    NATIVE_Text_from_clipboard = @
    "RESULT = AL4_clipboard.Get_text_from_clipboard();"

    NATIVE_Text_to_clipboard = @
    "AL4_clipboard.Set_text_to_clipboard(X_Text);"
    
    NATIVE_Clipboard_has_text = @
    "RESULT = AL4_clipboard.Is_text_in_clipboard();"
    

    NATIVE_Files_from_clipboard = @
    "RESULT = AL4_clipboard.Get_files_from_clipboard(X_Paths);"

    NATIVE_Files_to_clipboard = @
    "AL4_clipboard.Files_to_clipboard(X_Paths, X_Op);"

    NATIVE_Clipboard_has_files = @
    "RESULT = AL4_clipboard.Clipboard_has_files();"
    
    .
        
    */

}

/*
END
*/
