/*

CLASS {AL4_dir_dialog|s_csharp}, NATIVE, UNTESTED :
      
IMPORT: {Control}, {Dialog_dir} .

NATIVE: "using System.Windows.Forms;" .

*/
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
    {
        
        public class PanelDialogDir : Panel
        {
            public FolderBrowserDialog DialogObject;
        }
        
/*
        // Create directory select dialog
        //---------------------------------------------------------------------
        
        FUN Create_dir_dialog(
            INT F|orm_handle, 
            {Control} D|ialog_control) ==> INT, NATIVE :
        @   "   RESULT = AL4Form.Do_Create_dir_dialog((int)X_F, X_D);" .
        
FUN Execute|_dialog(
{Dialog_dir} D|ialog_control) ==> BOOL := D.Show_dir_dialog .    

*/
        public static int Do_Create_dir_dialog(int H, Ref_obj X_D)
        {
            AL4Column P = AL4Form.Get_parent_for_new_control(H);
            PanelDialogDir D = new PanelDialogDir();
            int Result = AL4Form.AllocDescriptor(D);
            D.Tag = X_D;
            D.Parent = P;
            D.Visible = false;
            D.Enabled = false;
            D.Size = new Size(0, 0);
            D.DialogObject = new FolderBrowserDialog();
            return Result;
        }


/*
        // Show directory dialog, return TRUE if directory was selected.
        //-----------------------------------------------------
        
        FUN Show_dir_dialog(
        {Control} C|ontrol_dialog_file//INT D|ialog_control
        ) ==> BOOL, NATIVE:
		INT h|andle_dialog = C.Handle
		INT f|orm_handle = C.Form_.Handle
		NATIVE @
            "    return AL4Form.Do_Show_dir_dialog((int)X_h, (int)X_f);" .
*/
        
        public static bool Do_Show_dir_dialog(int X_D, int X_F)
        {
            PanelDialogDir DP = (PanelDialogDir)AL4Form.All_descriptors[X_D];
            Ref_obj DRef = (Ref_obj)DP.Tag;
            C_Dialog_dir CD = (C_Dialog_dir)DRef.Obj;
            
                FolderBrowserDialog DD = DP.DialogObject;
                DD.Description = CD.F_Title;
            
            DD.Reset();
            DD.RootFolder = Environment.SpecialFolder.MyComputer;
            if (CD.F_Initial_path != "") {
            	string p = CD.F_Initial_path;
            	if (p[p.Length-1] != '\\') p = p + "\\";
            	
            	//AL4_system.WriteLine(p);
            	
            	DD.SelectedPath = p;
            	DD.SelectedPath = "";
            	DD.SelectedPath = p;
            }
            
            SendKeys.Send("{TAB}{TAB}{RIGHT}");
            AL4Form af = (AL4Form)AL4Form.All_descriptors[X_F];
            bool Result = DD.ShowDialog(af) == DialogResult.OK;
            if (Result)
                CD.F_Path = DP.DialogObject.SelectedPath;
            return Result;
        }

    }

} 

/*
END
*/
