(*
/*

//-------------- wrapper for {Dialog_dir}

CLASS {AL4_dir_dialog|_Delphi_VCL}, NATIVE, UNTESTED :
      
IMPORT: {Screen}, {Form}, {Dialog}, {Control}, {Dialog_dir} .
IMPORT, ANYWAY: {Select_dir} .

NATIVE:@"uses AL4_form, AL4_dir_dialog"
		", Forms, Controls, StdCtrls"
		" {$IFDEF LINUX}"
		" {$ELSE}"
		"		 ,Windows "
		" {$ENDIF} ;" .

NATIVE: "{$I AL4_options.inc}" .	
*/
*)
unit AL4_dir_dialog;

interface

{$I AL4_options.inc}

uses Classes, Forms, Controls, Menus, FileCtrl,
// use AL4 to access system functions (AL4.pas inserted by the compiler into
// a project folder)
     AL4, AL4_form,
// use All_classes from a project folder (generated for a certain project)
     All_classes,
     {$IFDEF FPC}
     {$ENDIF}
     StdCtrls, ExtCtrls, ComCtrls, Dialogs;

function Do_Create_dialog_dir(P: Integer; X_D: Pointer): Integer;
function Do_Show_dir_dialog(X_D: Integer): Boolean;

implementation

uses SysUtils {$IFDEF FPC}, UnitC_AL4_dir_dialog {$ENDIF};

(*
/*
// Create directory dialog
//----------------------------------------------------------------------------

FUN Create_dir_dialog(
    INT F|orm_handle,
    {Control} D|ialog_control) ==> INT, NATIVE :
    "     RESULT := Do_Create_dialog_dir(X_F, X_D);" .
*/
*)

type
    TPanelDialogDir = class(TPanel)
    	public destructor Destroy; override;
    end;
    
destructor TPanelDialogDir.Destroy;
begin
	{$IFDEF USE_LISTS_OF_DESCRIPTORS}
	release_control(Self);
	{$ENDIF}
	inherited;
end;

function Do_Create_dialog_dir(
P: Integer; X_D: Pointer): Integer;
var Parent: TAL4Column;
    D: TPanelDialogDir;
    F: TAL4Form;
begin
	{$IFDEF USE_LISTS_OF_DESCRIPTORS}
    	F := TAL4Form(All_forms[P]);
	{$ELSE}
    	F := TAL4Form(P);
	{$ENDIF}
    Parent := F.Get_current_column;
    D := TPanelDialogDir.Create(Parent);
	D.Tag := {$IFDEF FPC} IntPtr {$ELSE} Int64 {$ENDIF}(X_D);
    D.Parent := Parent;
    D.Width := 0;
    D.Height := 0;
    D.Visible := FALSE;
    {$IFDEF USE_LISTS_OF_DESCRIPTORS}
    	Result := allocate_control(D);
    	///////////////////////////////////////////////////////
    	//writeln('created TPanelDialogDir=' + IntToStr(RESULT));
    {$ELSE}
    	Result := Integer(D);
    {$ENDIF}
end;

(*
/*
// Show dir dialog, return TRUE if directory was selected.
//-----------------------------------------------------

FUN Show_dir_dialog(
{Control} C|ontrol_dialog_file) ==> BOOL, NATIVE:
	INT h|andle_dialog = C.Handle
	//DEBUG: << "show dir dialog " h.S #NL ;
	CASE h == 0 ? ==> ;
	NATIVE @
    "    RESULT := Do_Show_dir_dialog(X_h);"
    //////////////////////////////////
    //"	 writeln('RESULT of Show_dir_dialog=' + IntToStr(Integer(RESULT)));" 
    .
    
FUN Execute|_dialog(
{Dialog_dir} D|ialog_control) ==> BOOL := D.Show_dir_dialog .

FUNCTION Select_directory(
	{Form} Parent_form, STR Initial_dir|ectory) ==> STR, CALLBACK
	:
	{Select_dir} temp|_dialog_select_dir = {Select_dir}(
		Screen_= Parent_form.Screen_, Initial_dir= Initial_dir)
		
	//DEBUG: << "ShowModal for {Select_dir}, Parent=" Parent_form.Alias #NL ;
	CASE temp.Show_modal(Parent_form) == "OK" ?
	     //DEBUG: << "result is [" temp.Path "]"#NL ;
	     RESULT = temp.Path ; 
	
	Parent_form.Process .

*/
*)

function Do_Show_dir_dialog(
X_D: Integer): Boolean;
var DP: TPanelDialogDir;
    CD: C_Dialog_dir;
    RD: Ref_obj;
    IP: String;
begin
	Result := false;
	{$IFDEF USE_LISTS_OF_DESCRIPTORS}
    	DP := TPanelDialogDir(All_controls[X_D]);
	{$ELSE}
    	DP := TPanelDialogDir(X_D);
	{$ENDIF}
    RD := ref_obj_from_control(DP);
    CD := C_Dialog_dir(RD.Obj);
    IP := '';
    if DirectoryExists(CD.F_Initial_path {$IFDEF FPC} .As_string {$ENDIF} ) then 
    	IP := CD.F_Initial_path {$IFDEF FPC} .As_string {$ENDIF} ;
    {$IFDEF FPC}
	    CD.F_Path.Assign_string(M_Select_directory(CD.F_Form_, IP));
	    RESULT := Compare_strings(CD.F_Path, '') <> 0;
    {$ELSE}
    	Result := SelectDirectory(CD.F_Title, IP, CD.F_Path);
    {$ENDIF}
end;

end.
(*
/*
END
*/
*)



