(*
/*

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

NATIVE: @
        "uses AL4_form, AL4_datepicker;" .
*/
*)
unit AL4_datepicker;
{$I EXTERNAL_DEFINES.inc}
{$I KOLDEF.inc}

interface

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, AL4_form,
// use All_classes from a project folder (generated for a certain project)
     All_classes, unitC_Canvas,
     Windows, Messages;

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

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

implementation

uses err, 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);" .
*/
*)
function Do_Create_datepicker(P: Integer; X_D: Pointer): Integer;
var Parent: PAL4Column;
    D: PControl;
    F: PAL4Form;
begin
    F := PAL4Form(P);
    Parent := PAL4Column(F.Get_current_column_handle);
    D := NewDateTimePicker(Parent.Panel, [dtpoDateLong]);
    D.Width := 120;
    D.Tag := Integer(X_D);
    PObj(X_D).Tag := DWORD(D);
    
    D.DateTime := Trunc(Now);
    Adjust_control_location(Parent, D);
    Set_control_events(Parent, D);
    Set_Win_control_events(Parent, D);
    D.OnChange := PAL4Form(Parent.AL4Form).Control_changed;
    Result := Integer(D);
end;

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

FUN Get_date_picker_date(
INT D|atepicker_control) ==> {Date_time}.{date_time}
	:= Date_time(DT = do_Get_date_picker_date(D)) .
FUN do_Get_date_picker_date(INT D|atepicker_control) ==> REAL, NATIVE : @
"var D: PControl;"
   "D := PControl(X_D);"
   "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: PControl;"
   "D := PControl(X_D);"
   "{$IFNDEF NOEXCEPTIONS}"
   "TRY"
   "{$ENDIF}"
   "	D.Date := X_Value / 24.0 / 3600000;"
   "{$IFNDEF NOEXCEPTIONS}"
   "EXCEPT on E: Exception do"
   "	begin"
   "		Any_exception(E);"
   "	end;"
   "END;"
   "{$ENDIF}"
   .
   
// 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: PControl;
begin
    D := PControl(X_D);
    Result := DateTime2StrShort(D.Date);
end;

end.
(*
/*
END
*/
*)



