#include <fivewin.ch>
#include <calendar.ch>
// MyCalendar
#define MCMV_MONTH 0
#define MCMV_YEAR 1
#define MCMV_DECADE 2
#define MCMV_CENTURY 3
#define MCMV_MAX MCMV_CENTURY
// TEST CODE
proc main()
LOCAL oDlg, oMonth, dData1 := Date(),dData2 := Date(), oMonth2, dMese := Date()
DEFINE DIALOG oDlg SIZE 700,400 PIXEL TRUEPIXEL;
TITLE "Test MonthCal" RESIZABLE
//@ 10,10 CALENDAR oMonth VAR dData1,dData2 PIXEL NOTADAY NOTODAYCIRCLE SIZE 500,20
oMonth := MyCalendar():New( 10, 10, { | u | If( PCount()==0, dData1, dData1:= u ) }, { | u | If( PCount()==0, dData2, dData2:= u ) },, 500, 20,,,,, .F.,, .T.,, .F., .F.,,,,,, .F., .T., .T., .F. )
// only month calendar test
//@ 210,10 CALENDAR oMonth2 VAR dMese PIXEL NOTADAY NOTODAYCIRCLE SIZE 700,20
oMonth2 := MyCalendar():New( 210, 10, { | u | If( PCount()==0, dMese, dMese:= u ) }, nil,, 700, 160,,,,, .F.,, .T.,, .F., .F.,,,,,, .F., .T., .T., .F. )
oMonth2:bViewChanged := {|Self,nOld,nNew| iif(nNew<MCMV_YEAR,::SetCurrentView(MCMV_YEAR),) }
oDlg:bResized := <||
local oRect := oDlg:GetCliRect()
oMonth2:nWidth := oRect:nRight
return nil
>
ACTIVATE DIALOG oDlg CENTERED;
ON INIT (oMonth2:SetCurrentView(MCMV_YEAR),EVAL( oDlg:bResized))
// MyCalendar
#define SWP_NOSIZE 0x0001
#define SWP_NOMOVE 0x0002
#define SWP_NOZORDER 0x0004
#define MCN_VIEWCHANGE (-750)
CLASS MyCalendar FROM TCalendar
DATA bViewChanged
METHOD New(...) CONSTRUCTOR
METHOD HandleEvent( nMsg, nWParam, nLParam )
METHOD Change()
METHOD Notify( nIdCtrl, nPtrNMHDR )
// use SetGet?
METHOD Initiate( hDlg )
METHOD SetCurrentView(id) INLINE MonthCal_SetCurrentView(::hWnd, id)
METHOD GetCurrentView() INLINE MonthCal_GetCurrentView(::hWnd)
endclass
METHOD New(...) CLASS MyCalendar
LOCAL rc
::Super:new(...)
if !Empty( ::hWnd )
rc := MonthCal_SizeRectToMin( ::hWnd, GetClientRect( ::hWnd ) )
SetWindowPos(::hWnd, 0, 0, 0, rc[4], rc[3], nOr(SWP_NOZORDER, SWP_NOMOVE))
::CoorsUpdate()
endif
return Self
METHOD Initiate( hDlg ) CLASS MyCalendar
LOCAL rc
::Super:Initiate(hDlg)
if !Empty( ::hWnd )
rc := MonthCal_SizeRectToMin( ::hWnd, GetClientRect( ::hWnd ) )
SetWindowPos(::hWnd, 0, 0, 0, rc[4], rc[3], nOr(SWP_NOZORDER, SWP_NOMOVE))
::CoorsUpdate()
endif
return nil
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS MyCalendar
// TODO: Verify others messages
if nMsg==WM_LBUTTONUP
::Super:HandleEvent( nMsg, nWParam, nLParam )
endif
return nil
METHOD Change() CLASS MyCalendar
local aTmp
static dOldDate, dOldDate2
if ::bChange != nil
if ::lMultiselect
aTmp := ::GetDateRange()
if dOldDate != aTmp[1] .or. dOldDate2 != aTmp[2]
Eval( ::bChange, Self )
dOldDate := aTmp[1]
dOldDate2 := aTmp[2]
endif
else
if dOldDate != ::GetDate()
Eval( ::bChange, Self )
dOldDate = ::GetDate()
endif
endif
endif
return NIL
METHOD Notify( nIdCtrl, nPtrNMHDR ) CLASS MyCalendar
local nCode := GetNMHDRCode( nPtrNMHDR ), nOld, nNew
if nCode == MCN_VIEWCHANGE
if !empty(::bViewChanged)
MonthCal_GetViewChangeValues(nPtrNMHDR, @nOld, @nNew)
eval(::bViewChanged, self, nOld, nNew)
endif
return nil
endif
return ::Super:Notify( nIdCtrl, nPtrNMHDR )
//----------------------------------------------------------------------------//
#pragma BEGINDUMP
#include <Windows.h>
#include <CommCtrl.h>
#include <hbapi.h>
#include <hbdate.h>
#include <fwh.h>
//----------------------------------------------------------------------------//
HB_FUNC( MONTHCAL_GETMINREQRECT ) // hWnd --> { nTop, nLeft, nBottom, nRight }
{
HWND hWnd = ( HWND ) fw_parH( 1 );
RECT rct;
rct.top = 0;
rct.left = 0;
rct.bottom = 0;
rct.right = 0;
if( hWnd )
MonthCal_GetMinReqRect( hWnd, &rct );
hb_reta( 4 );
hb_storvni( rct.top, -1, 1 );
hb_storvni( rct.left, -1, 2 );
hb_storvni( rct.bottom, -1, 3 );
hb_storvni( rct.right, -1, 4 );
}
//----------------------------------------------------------------------------//
HB_FUNC( MONTHCAL_SIZERECTTOMIN ) // hWnd,{ nTop, nLeft, nBottom, nRight } --> { nTop, nLeft, nBottom, nRight }
{
HWND hWnd = ( HWND ) fw_parH( 1 );
RECT rct;
rct.top = hb_parvni( 2, 1 );
rct.left = hb_parvni( 2, 2 );
rct.bottom = hb_parvni( 2, 3 );
rct.right = hb_parvni( 2, 4 );
if( hWnd )
MonthCal_SizeRectToMin( hWnd, &rct );
hb_reta( 4 );
hb_storvni( rct.top, -1, 1 );
hb_storvni( rct.left, -1, 2 );
hb_storvni( rct.bottom, -1, 3 );
hb_storvni( rct.right, -1, 4 );
}
//----------------------------------------------------------------------------//
HB_FUNC( MONTHCAL_SETCURRENTVIEW ) // hWnd, id
{
MonthCal_SetCurrentView(( HWND ) fw_parH( 1 ), hb_parni( 2 ));
}
//----------------------------------------------------------------------------//
HB_FUNC( MONTHCAL_GETCURRENTVIEW ) // hWnd -> id
{
hb_retni(MonthCal_GetCurrentView(( HWND ) fw_parH( 1 )));
}
//----------------------------------------------------------------------------//
HB_FUNC( MONTHCAL_GETVIEWCHANGEVALUES ) // NMVIEWCHANGE, @bOld, @nNew
{
LPNMVIEWCHANGE lParam = (LPNMVIEWCHANGE) fw_parH( 1 );
hb_storni(lParam->dwOldView, 2 );
hb_storni(lParam->dwNewView, 3 );
}
#pragma ENDDUMP