(*
/*

CLASS {AL4_datepicker|_Delphi}, NATIVE, UNTESTED :
      IMPORT: {Control}, {Date_time} ;

NATIVE: "uses AL4_form, AL4_datepicker"
		", Forms, Controls, StdCtrls"
		" {$IFDEF LINUX}"
		" {$ELSE}, Windows "
		" {$ENDIF} ;" .
		
NATIVE: "{$I AL4_options.inc}" .		
*/
*)
unit AL4_datepicker;

{$I AL4_options.inc}

interface

{$I AL4_options.inc}

uses Classes, Forms, Controls, Menus,
// 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, unitC_Canvas,
     {$IFDEF FPC}
     	datetimepicker,
     {$ENDIF}
     StdCtrls, ExtCtrls, ComCtrls, Dialogs
     {$IFDEF LINUX}
     {$ELSE} , Windows, Messages
     {$ENDIF};


// datepicker functions
function Do_Create_datepicker(P: Integer; X_D: Pointer): Integer;
function Do_Get_datepicker_text(X_D: Integer): String;

type TAL4DatePicker = class(TDateTimePicker)
		destructor Destroy; override;
	 end;
	 

implementation

uses SysUtils, unitC_Control;

//------------------------------------------------------ D A T E  P I C K E R

(*
/*
// Create date picker control, return descriptor
//----------------------------------------------

FUN Create_date_picker(
	{Control} D|atepicker_control) ==> INT
	:
    RESULT = do_create_datepicker(D.Form_.Handle, D) .

FUN do_create_datepicker(INT F|orm_handle,
    {Control} D|atepicker_create) ==> INT, NATIVE :
    "     Result := Do_Create_datepicker(X_F, X_D);" .
*/
*)

destructor TAL4DatePicker.Destroy;
begin
	{$IFDEF USE_LISTS_OF_DESCRIPTORS}
	release_control(Self);
	{$ENDIF}
	inherited;
end;

function Do_Create_datepicker(
P: Integer; X_D: Pointer): Integer;
var Parent: TAL4Column;
    D: TAL4DatePicker;
    F: TAL4Form;
begin
	F := form_from_handle(P);
    Parent := F.Get_current_column;
    D := TAL4DatePicker.Create(Parent);
    {$IFDEF FPC}                                        
    D.AutoSize := FALSE;
    {$ENDIF}
    D.Width := 120;
    {$IFNDEF FPC}
    	D.DateFormat := dfLong;
    {$ENDIF}
    {$IFDEF CPU64}
    	D.Tag := {$IFDEF FPC} IntPtr {$ELSE} Int64 {$ENDIF}(X_D);
    {$ELSE}
    	D.Tag := Integer(X_D);
    {$ENDIF}
    D.Parent := Parent;
    D.DateTime := Trunc(Now);
    Adjust_control_location(Parent, D);
    Set_control_events(Parent, D);
    Set_Win_control_events(Parent, D);
    D.OnChange:={$IFDEF OBJFPC}@{$ENDIF}TAL4Form(Parent.Parent).Control_changed;
    {$IFDEF USE_LISTS_OF_DESCRIPTORS}
    	Result := allocate_control(D);
    {$ELSE}
    	Result := Integer(D);
    {$ENDIF}
end;

(*
/*
// Get date picker date
//---------------------

FUN Get_date_picker_date(
INT D|atepicker_control) ==> {Date_time}.{date_time}
	:
	CASE D == 0 ? ==> ;
	RESULT = Date_time(DT = do_Get_date_picker_date(D)) .
FUN do_Get_date_picker_date(INT D|atepicker_control) ==> REAL, NATIVE : @
"var D:TAL4DatePicker;"
   "{$IFDEF USE_LISTS_OF_DESCRIPTORS}"
   "	D := TAL4DatePicker(All_controls[X_D]);"
   "{$ELSE}"
   "	D := TAL4DatePicker(X_D);"
   "{$ENDIF}"
   "Result := D.Date * 24.0 * 3600000;"
   .
   
// Set date picker date
//---------------------

FUN Set_date_picker_date(
INT D|atepicker_control, {date_time} Value|_date)
	:
	do_Set_date_picker_date(D, Value.DT) .
FUN do_Set_date_picker_date(
INT D|atepicker_control, REAL Value|_to_set), NATIVE : @
"var D:TAL4DatePicker;"
   "{$IFDEF USE_LISTS_OF_DESCRIPTORS}"
   "	D := TAL4DatePicker(All_controls[X_D]);"
   "{$ELSE}"
   "	D := TAL4DatePicker(X_D);"
   "{$ENDIF}"
   "TRY"
   "	D.Date := X_Value / 24.0 / 3600000;"
   "EXCEPT on E: Exception do"
   "	begin"
   "		Any_exception(E);"
   "	end;"
   "END;"
   .
   
// Get date picker text
//---------------------
FUN Get_date_picker_text(INT D|atepicker_control) ==> STR, NATIVE : @
    "    RESULT := Do_Get_datepicker_text(X_D);" . 
*/
*)
function Do_Get_datepicker_text(X_D: Integer): String;
var D:TAL4DatePicker;
begin
	{$IFDEF USE_LISTS_OF_DESCRIPTORS}
		D := TAL4DatePicker(All_controls[X_D]);
	{$ELSE}
    	D := TAL4DatePicker(X_D);
	{$ENDIF}
    {$IFDEF FPC}
    Result := DateToStr(D.Date);      
    {$ELSE}
    Result := FormatDateTime({$IFDEF _D6orHigher} D.Format {$ELSE} '' {$ENDIF},
    		  D.Date);
    {$ENDIF}
end;

(*
/*
END
*/
*)
end.
