/*

CLASS {AL4_tray|_csharp}, NATIVE, UNTESTED :

IMPORT: {Control}, {Icon} .

NATIVE: @
        "using System.Windows.Forms;"
        "using System.Drawing;" .
        
NATIVE: "///COPY: AL4_tray.cs" .

*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

using System.Runtime.InteropServices;

using AL4;
using AL4_project;

namespace AL4
{

    public partial class AL4Form : Form
    {

        //------------------------------------------------------------ T R A Y
        /*
        // Create tray icon component.
        //----------------------------------------------------------------------
        FUN Create_tray_icon({Control} T|ray_icon_object, 
            {Icon} Icon|_handle) ==> INT
            :
            ------------------------------------------------- 'Create tray icon'
            RESULT = do_create_tray_icon(T.Form_.Handle, T, Icon) .

        FUN do_create_tray_icon( INT F|orm_handle,
            {Control} T|imer_create, {Icon} Icon|_handle) ==> INT,
            NATIVE :
			CASE Icon == NONE ? ==> ;
			NATIVE @
        @   "   RESULT = AL4Form.Do_Create_tray_icon((int)X_F, X_T, X_Icon);" 
            "   AL4Form.Do_replace_tray_icon((int)RESULT, X_Icon);" .
        */
        public static int Do_Create_tray_icon(int H, Ref_obj X_T, Ref_obj X_Icon)
        {
            AL4Column P = Get_parent_for_new_control(H);
            AL4Form F = (AL4Form)P.Parent;
            TrayPanel TP = new TrayPanel();
            int Result = AL4Form.AllocDescriptor(TP);
            TP.Tag = X_T;
            //TP.Parent = P;
            P.Controls.Add(TP);
            TP.Visible = false;
            TP.Enabled = false;
            TP.Size = new Size(0, 0);
            TP.TrayObject = new NotifyIcon();
            TP.TrayObject.MouseClick += new MouseEventHandler(TP.Form_tray_icon_click);
            TP.TrayObject.Tag = X_T;
            
            F.Trays_timers.Add(TP);
            
            return Result;
        }
        
        static Icon empty_icon;
        public static void Do_replace_tray_icon(int X_Handle, Ref_obj X_Icon)
        {
//?{Icon}
			if (X_Icon == null) return;
            TrayPanel TP = (TrayPanel)AL4Form.All_descriptors[(int)X_Handle];
            C_Icon ico = (C_Icon)X_Icon.Obj;
            Icon i = null;
            if (ico.F_Handle != 0)
            {
                BitmapEx b = (BitmapEx)AL4Form.All_bitmaps[(int)ico.F_Handle];
                i = b.Ico;
                if (i != null)
                    TP.TrayObject.Icon = i;
            }
            if (i == null)
            {
                if (empty_icon == null)
                {
                    Bitmap ebitmap = new Bitmap(16, 16);
                    IntPtr Hicon = ebitmap.GetHicon();
                    empty_icon = Icon.FromHandle(Hicon);
                }
                TP.TrayObject.Icon = empty_icon;
            }
//.
        
        /*
        //----------------------------------------------------------------------------
        FUN Set_tray_icon_active( INT Handle|_tray_icon_object, 
            BOOL Active|_value ), NATIVE :
			CASE Handle == 0 ? ==> ;
			NATIVE @
            "TrayPanel TP = (TrayPanel)AL4Form.All_descriptors[(int)X_Handle];"
            "TP.TrayObject.Visible = X_Active;"
            .
            
        // Set tray icon text.
        //----------------------------------------------------------------------------
        FUN Set_tray_icon_text( INT Handle|_tray_icon_object, 
            STR S|how_text ), NATIVE :
			CASE Handle == 0 ? ==> ;
			NATIVE @
            "TrayPanel TP = (TrayPanel)AL4Form.All_descriptors[(int)X_Handle];"
            "TP.TrayObject.Text = X_S;" .
            
        // Destroy try icon object.
        //----------------------------------------------------------------------------
        FUN Destroy_tray_icon( INT Handle|_tray_icon_object), NATIVE :
       @"     TrayPanel TP = (TrayPanel)AL4Form.All_descriptors[(int)X_Handle];"
        "     TP.TrayObject.Visible = false;"
        "     TP.TrayObject = null;"
        ""
        "   AL4Form form = AL4Form.Parent_form(TP);"
        "   form.Trays_timers.Remove(TP);"
        ""
        "     AL4Form.ReleaseDescriptor((int)X_Handle);" .
            
        // Destroy icon.
        //----------------------------------------------------------------------------
        FUN Destroy_icon( INT Handle|_icon), NATIVE :
           @"     if (X_Handle > 0) AL4Form.ReleaseDescriptor((int)X_Handle);" .
            
        // Load icon from file.
        //----------------------------------------------------------------------------
        FUN Load_icon_from_file( STR Path|_to_file_containing_icon ) ==> INT,
            NATIVE :
           @"     try {"
            "       Icon i = new Icon(X_Path);" 
            "       int h = AL4Form.AllocDescriptor(i);"
            "       return h;"
            "     }"
            "     catch (Exception e) {"
            "           AL4_system.Any_exception(e);"
            "           return 0;"
            "     }" .
            
        // Replace tray icon by another icon object
        //----------------------------------------------------------------------
        FUN Replace_tray_icon( INT Handle|_tray_icon_object,
            {Icon} Value|_icon_to_set ), NATIVE :
			CASE Handle == 0 ? ==> ;
			NATIVE @
            "   AL4Form.Do_replace_tray_icon((int)X_Handle, X_Value);" .
        */        
    
    	}
    
	}
	
}
    
/*
END
*/







