(*
/*

//-------------- wrapper for {Dialog_file}

CLASS {AL4_file_dialog|s_Delphi}, NATIVE, UNTESTED :
      IMPORT: {Control};

NATIVE: "uses AL4_file_dialog, Windows;" .
*/
*)
unit AL4_file_dialog;

interface

{$I KOLDEF.inc}

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

//{$WARN UNIT_DEPRECATED OFF}
//{$WARN SYMBOL_PLATFORM OFF}
//{$WARN UNSAFE_TYPE OFF}
//{$WARN UNSAFE_CAST OFF}
//{$WARN UNSAFE_CODE OFF}

type
    PPanelDialogFile = ^TPanelDialogFile;
    TPanelDialogFile = object(TObj)
        DialogObject: POpenSaveDialog;
    end;


function Do_Create_dialog_file(P: Integer; X_D: Pointer;
         X_Save: Boolean): Integer;
function Do_Show_file_dialog(X_D: Integer): Boolean;

implementation

(*
/*
// Create file dialog, either save dialog or open dialog.
//----------------------------------------------------------------------------
FUN Create_file_dialog({Control} D|ialog_control,
    BOOL Save|_dialog) ==> INT
    :
    RESULT = do_create_file_dialog(D.Form_.Handle, D, Save) .

FUN do_create_file_dialog(INT F|orm_handle,
    {Control} D|ialog_control, BOOL Save|_dialog) ==> INT, NATIVE :
    "     Result := Do_Create_dialog_file(X_F, X_D, X_Save);" .
*/
*)
function Do_Create_dialog_file(P: Integer; X_D: Pointer;
         X_Save: Boolean): Integer;
var Parent: PAL4Column;
    D: PPanelDialogFile;
    F: PAL4Form;
begin
    F := PAL4Form(P);
    Parent := PAL4Column(F.Get_current_column_handle);
    new(D, Create);
    D.Tag := Integer(X_D);
    PObj(X_D).Tag := DWORD(D);
    //------------------------- 'create DialogObject'
    D.DialogObject := NewOpenSaveDialog('', '', []);
    D.DialogObject.OpenDialog := not X_Save;
    Result := Integer(D);
end;

(*
/*
// Show file dialog, return TRUE if  file was selected.
//-----------------------------------------------------
FUN Show_file_dialog({Control} D|ialog_control) ==> BOOL, NATIVE:
	INT h|andle_dialog = D.Handle
	NATIVE @
    "    RESULT := Do_Show_file_dialog(X_h);" .
*/
*)
function Do_Show_file_dialog(X_D: Integer): Boolean;
var DP: PPanelDialogFile;
    D: POpenSaveDialog;
    CD: C_Dialog_file;
    RD: Ref_obj;
    oop: TOpenSaveOptions;
    s: String;
    i: Integer;
begin
    DP := PPanelDialogFile(X_D);
    RD := Pointer(DP.Tag);
    CD := C_Dialog_file(RD.Obj);
    D := DP.DialogObject;
    D.Title := CD.F_Title;
    D.InitialDir := CD.F_Initial_path;
    D.DefExtension := CD.F_Default_ext;
    D.Filter := CD.F_Filter;
    D.Filename := CD.F_Filename;
    
	oop := D.Options;
    if CD.F_Multiselect then include(oop, OSAllowMultiSelect)
    else exclude(oop, OSAllowMultiSelect);
    D.Options := oop;
    
    Result := D.Execute;
    if  Result then
    begin
    	s := D.Filename;
    	if CD.F_Multiselect then
    	begin
    		for i := 1 to Length(s) do
    			if (s[i]=#13) then s[i] := ';';
    	end;
        CD.F_Filename := s;
    end;
end;

end.
(*
/*
END
*/
*)



