thank you for helping to develop pickdate as control class.
Now I have the movemouse method ready.
Would you please help again to show me how to implement redefine and how to use
this control from a resource.
Please uncomment SET DATE TO GERMAN and use ENGLISH in func RegionDate(nMonth,cYear ).
Here is the code:
- Code: Select all Expand view
#include "FiveWin.ch"
//----------------------------------------------------------------------------//
function Main()
local oWnd, oPickDate
SET DATE TO GERMAN
DEFINE WINDOW oWnd TITLE "Calendar"
oPickDate := TPickDate():New( 10, 10,,, oWnd )
oWnd:oClient = oPickDate
ACTIVATE WINDOW oWnd MAXIMIZED
return nil
//----------------------------------------------------------------------------//
CLASS TPickDate FROM TControl
DATA dStart, dEnd, lMove
DATA hBru
DATA nYear
DATA oBrushSunday
DATA nLeftStart
DATA nTopStart
DATA startDay,endDay,TmpEndDay
DATA oFontHeader
CLASSDATA lRegistered AS LOGICAL
METHOD New( nTop, nLeft, nWidth, nHeight, oWnd, nYear, nClrFore, nClrBack )
METHOD Paint()
METHOD Display() INLINE ::BeginPaint(), ::Paint(), ::EndPaint(), 0
METHOD End()
METHOD LButtonDown( nRow, nCol, nKeyFlags )
METHOD LButtonUp( nRow, nCol, nKeyFlags )
METHOD PreviousYear() INLINE ::nYear--, ::Refresh()
METHOD NextYear() INLINE ::nYear++, ::Refresh()
METHOD EraseBkGnd( hDC ) INLINE 0
METHOD MouseMove( nRow, nCol, nKeyFlags )
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New( nTop, nLeft, nWidth, nHeight, oWnd, nYear, nClrFore, nClrBack ) CLASS TPickDate
local IMonate
DEFAULT nWidth := 800,;
nHeight := 300,;
nLeft := 0,;
nTop := 0,;
nYear := Year( Date() ),;
oWnd := GetWndDefault()
::lMove =.f.
::nTopStart = 60 // for header
::nLeftStart = 150 // col header
::nTop = nTop
::nLeft = nLeft
::nBottom = nTop + nHeight - 1
::nRight = nLeft + nWidth - 1
::nYear = Year( Date() )
::oWnd = oWnd
::startDay = date()
::endDay = date()
::TmpEndDay = date()
::nClrText = nClrFore
::nClrPane = nClrBack
::nStyle = nOr( WS_CHILD, WS_VISIBLE, WS_TABSTOP, WS_BORDER )
::hBru = CreateSolidBrush( RGB(240,232,188) )
DEFINE BRUSH ::oBrushSunday COLOR nRGB( 183, 249, 185 ) // Sundays column green brush
DEFINE FONT ::oFont NAME "Tahoma" SIZE 0, -12 BOLD
DEFINE FONT ::oFontHeader NAME "Tahoma" SIZE 0, -12
#ifdef __XPP__
DEFAULT ::lRegistered := .F.
#endif
::Register( nOR( CS_VREDRAW, CS_HREDRAW ) )
if ! Empty( oWnd:hWnd )
::Create()
oWnd:AddControl( Self )
else
oWnd:DefControl( Self )
endif
return self
//----------------------------------------------------------------------------//
METHOD Paint() CLASS TPickDate
local aInfo := ::DispBegin()
local hDC := ::hDC, cDay, nDay, n:=0, dDate, nColStep, nRowStep
local dTmpDate, nMonth := 0
local nLeftCol:=0
local IShow
FillRect( hDC, GetClientRect( ::hWnd ), ::oBrush:hBrush )
nRowStep = (::nHeight - ::nTopStart) / 13
GradientFill( hDC, 0, 0, ::nHeight, ::nWidth, { { 1, nRGB( 128, 217, 255 ), nRGB( 54, 147, 255 ) } } )
dDate = CToD( "01/01/" + Str( ::nYear, 4 ) )
nColStep = ( ::nWidth - ::nLeftStart ) / 37
GradientFill( hDC, 0, 0, nRowStep - 1, ::nWidth, { { 1, nRGB( 128, 217, 255 ), nRGB( 54, 147, 255 ) } } )
::Say( (::nTopStart +( nRowStep / 2 ) - ( ::oFont:nHeight / 2 )),;
( ( ::nLeftStart + nColStep ) / 2 ) - ( GetTextWidth( hDC, Str( ::nYear, 4 ), ::oFont:hFont ) / 2 ),;
Str( ::nYear, 4 ),,, ::oFont, .T., .T. )
// Paint Sunday background color
for n = 1 to 36 step 7
FillRect( hDC, { 0, ::nLeftStart+ ( nColStep * n ), ::nHeight - 1, ::nLeftStart + ( nColStep * ( n + 1 ) ) }, ::oBrushSunday:hBrush )
next
for nMonth = 1 to 12
::Line(::nTopStart + nMonth * nRowStep, 0,(::nTopStart + nMonth * nRowStep), ::nWidth - 1 )
::Say( ::nTopStart + nMonth * nRowStep + ( nRowStep / 2 ) - ( ::oFont:nHeight / 2 ), 3, cMonth( RegionDate(nMonth, Str( Year( Date() ), 4 ))) ,,, ::oFont, .T., .T. )
next
*******************************************************************
* start show move mouse
*******************************************************************
IF ::lMove =.t.
dTmpDate := ::startDay
FOR IShow := 1 TO ::endDay + 1 - ::startDay
nMonth := month(dTmpDate)
nLeftCol := ::nLeftStart + ( nColStep * ( DOW(RegionDate(nMonth,Str( ::nYear, 4 ) ))) ) +;
nColStep * (Day( dTmpDate )-1)
FillRect(hDC, {::nTopStart + month(dTmpDate) * nRowStep,;
nLeftCol,;
::nTopStart + month(dTmpDate) * nRowStep + nRowStep ,;
nLeftCol + nColStep}, ::hBru )
dTmpDate := ::startDay + IShow
NEXT
ENDIF
*******************************************************************
* end show move mouse
*******************************************************************
// Draw days
for n = 1 to 36
::Line( 0, ::nLeftStart + ( nColStep * n ), ::nHeight - 1, ::nLeftStart + ( nColStep * n ) )
cDay = SubStr( CDoW( dDate ), 1, 2 )
::Say( (::nTopStart +nRowStep * 0.4),;
::nLeftStart + ( nColStep * n ) + ( nColStep / 2 ) - ( GetTextWidth( hDC, cDay, ::oFont:hFont ) / 2 ) + 1,;
cDay, 0, If( DoW( dDate++ ) == 1, nRGB(255,128,255),nRGB(0,187,187)), ::oFont, .T., .T. )
next
// Draw months
for nMonth = 1 to 12
dDate = RegionDate(nMonth,Str( ::nYear, 4 ) )
nDay = DoW( dDate )
while Month( dDate ) == nMonth
cDay = AllTrim( Str( Day( dDate ) ) )
::Say((::nTopStart + nMonth * nRowStep + ( nRowStep * 0.4 )),;
::nLeftStart + ( nColStep * nDay++ ) + ( nColStep / 2 ) - ( GetTextWidth( hDC, cDay, ::oFont:hFont ) / 2 ) + 1,;
cDay, 0, If( ! Empty( ::dStart ) .and. dDate >= ::dStart .and. dDate <= ::dEnd, nRGB( 178, 204, 235 ),;
If( DoW( dDate ) == 1, nRGB( 128, 233, 176 ),) ), ::oFontHeader, .T. )
dDate++
end
next
::DispEnd( aInfo )
return 0
//----------------------------------------------------------------------------//
METHOD End() CLASS TPickDate
::oBrushSunday:end()
return super:end()
//----------------------------------------------------------------------------//
METHOD LButtonDown( nRow, nCol, nKeyFlags ) CLASS TPickDate
local nMonth := Int( (nRow-::nTopStart) / (( ::nHeight - ::nTopStart )/ 13) )
local nDay := Int( ( nCol - ::nLeftStart ) / ( ( ::nWidth - ::nLeftStart ) / 37 )) - DoW( RegionDate(nMonth,Str( ::nYear, 4 ) ) ) + 1
IF nDay > 0 .AND. nMonth > 0 // to show only valid dates
::startDay := CToD( AllTrim( AllTrim( Str( nDay ) )+ "/" + Str( nMonth ) ) + "/" + Str( ::nYear, 4 ) )
::lMove := .t.
::refresh(.f.)
ENDIF
Super:LButtonDown( nRow, nCol, nKeyFlags )
return nil
//-----------------------------------------------------------------//
METHOD LButtonUp( nRow, nCol, nKeyFlags ) CLASS TPickDate
IF ::endDay - ::startDay > 0
msginfo(dtoc(::StartDay)+" "+ dtoc(::endDay))
ENDIF
::lMove := .f.
Super:LButtonUp( nRow, nCol, nKeyFlags )
return nil
//-----------------------------------------------------------------//
METHOD MouseMove( nRow, nCol, nKeyFlags ) CLASS TPickDate
local nMonth := Int( (nRow - ::nTopStart ) / (( ::nHeight - ::nTopStart )/ 13) )
local nDay := Int( ( nCol - ::nLeftStart ) / ( ( ::nWidth - ::nLeftStart ) / 37 )) - ;
DoW( RegionDate(nMonth,Str( ::nYear, 4 ) ) ) + 1
::endDay := CToD( AllTrim( AllTrim( Str( nDay ) )+ "/" + Str( nMonth ) ) + "/" + Str( ::nYear, 4 ) )
IF ::endDay <> ::TmpendDay // for reducing continuous refreshes
::TmpendDay := ::endDay
::refresh(.f.)
ENDIF
super:MouseMove( nRow, nCol, nKeyFlags )
return 0
func RegionDate(nMonth,cYear )
local dRegionDate
dRegionDate := CToD( "01/" + Str( nMonth, 2 ) + "/" + cYear )
//ENGLISH
//dRegionDate := CToD( Str( nMonth, 2 ) + "/" + "01/" + cYear )
return (dRegionDate)