METHOD PreviousYear() INLINE ::nYear--, ::Refresh()
METHOD NextYear() INLINE ::nYear++, ::Refresh()
#include "FiveWin.ch"
//----------------------------------------------------------------------------//
function Main()
local oWnd, oPickDate
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 ClickRow, hBru
DATA ClickCol
DATA nYear, syTemp
CLASSDATA lRegistered AS LOGICAL
METHOD New( nTop, nLeft, nWidth, nHeight, oWnd, nYear, nClrFore, nClrBack )
METHOD Paint()
METHOD Display() INLINE ::BeginPaint(), ::Paint(), ::EndPaint(), 0
METHOD LButtonDown( nRow, nCol, nFlags )
METHOD LButtonUp( nRow, nCol, nFlags )
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
DEFAULT nWidth := 800,;
nHeight := 300,;
nLeft := 0,;
nTop := 0,;
nYear := Year( Date() ),;
oWnd := GetWndDefault()
::lMove :=.f.
::nTop = nTop
::nLeft = nLeft
::nBottom = nTop + nHeight - 1
::nRight = nLeft + nWidth - 1
::nYear = Year( Date() )
::oWnd = oWnd
::nClrText = nClrFore
::nClrPane = nClrBack
::nStyle = nOr( WS_CHILD, WS_VISIBLE, WS_TABSTOP, WS_BORDER )
::syTemp:=0
::hBru := CreateSolidBrush( RGB(255,0,0) )
::ClickRow := 0
::ClickCol := 0
::nHeight := 0
::nWidth := 0
DEFINE FONT ::oFont 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(), nRowStep, nColStep, n, dDate
local hDC := ::hDC, cDay, oBrush, nDay, oFont := ::oFont
FillRect( hDC, GetClientRect( ::hWnd ), ::oBrush:hBrush )
DEFINE BRUSH oBrush COLOR nRGB( 183, 249, 185 ) // Sundays column green brush
nRowStep = ::nHeight / 13
//GradientFill( hDC, 0, 0, ::nHeight, ::nWidth, { { 1, nRGB( 128, 217, 255 ), nRGB( 54, 147, 255 ) } } )
for n = 1 to 12
::Line( n * nRowStep, 0, n * nRowStep, ::nWidth - 1 )
::Say( n * nRowStep + ( nRowStep / 2 ) - ( oFont:nHeight / 2 ), 3, cMonth( CToD( Str( n, 2 ) + "/01/" + ;
Str( Year( Date() ), 4 ) ) ),,, oFont, .T., .T. )
next
dDate = CToD( "06/01/" + Str( ::nYear, 4 ) )
nColStep = ( ::nWidth - 60 ) / 37
// GradientFill( hDC, 0, 0, nRowStep - 1, ::nWidth, { { 1, nRGB( 128, 217, 255 ), nRGB( 54, 147, 255 ) } } )
::Say( ( nRowStep / 2 ) - ( oFont:nHeight / 2 ),;
( ( 60 + nColStep ) / 2 ) - ( GetTextWidth( hDC, Str( ::nYear, 4 ), ::oFont:hFont ) / 2 ),;
Str( ::nYear, 4 ),,, oFont, .T., .T. )
for n = 1 to 36 step 7
FillRect( hDC, { 0, 60 + ( nColStep * n ), ::nHeight - 1, 60 + ( nColStep * ( n + 1 ) ) }, oBrush:hBrush )
next
IF ::lMove=.t.
FillRect(hDC, {::ClickRow,;
::ClickCol,;
::ClickRow + ( ::nHeight / 13 ),;
::syTemp}, ::hBru )
ENDIF
for n = 1 to 36
::Line( 0, 60 + ( nColStep * n ), ::nHeight - 1, 60 + ( nColStep * n ) )
cDay = SubStr( CDoW( dDate ), 1, 2 )
::Say( nRowStep * 0.4,;
60 + ( nColStep * n ) + ( nColStep / 2 ) - ( GetTextWidth( hDC, cDay, oFont:hFont ) / 2 ) + 1,;
cDay, 0, If( DoW( dDate++ ) == 1, nRGB( 128, 233, 176 ),), oFont, .T., .T. )
next
for n = 1 to 12
dDate = CToD( Str( n ) + "/01/" + Str( ::nYear, 4 ) )
nDay = DoW( dDate )
while Month( dDate ) == n
cDay = AllTrim( Str( Day( dDate ) ) )
::Say( n * nRowStep + ( nRowStep * 0.4 ),;
60 + ( 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 ),) ), oFont, .T. )
dDate++
end
next
// ::DispEnd( aInfo )
oBrush:End()
return 0
//----------------------------------------------------------------------------//
METHOD LButtonDown( nRow, nCol, nFlags ) CLASS TPickDate
local nMonth := Int( nRow / ( ::nHeight / 13 ) )
local nDay := Int( ( nCol - 60 ) / ( ( ::nWidth - 60 ) / 37 ) ) - ;
DoW( CToD( Str( nMonth ) + "/01/" + Str( ::nYear, 4 ) ) ) + 1
local dDate := CToD( AllTrim( Str( nMonth ) ) + "/" + AllTrim( Str( nDay ) ) + "/" + Str( ::nYear, 4 ) )
::lMove:=.t.
::ClickRow := Int( nRow / ( ::nHeight / 13 ) ) * ( ::nHeight / 13 )
::ClickCol := Int( ( nCol - 60 ) / ( ( ::nWidth - 60 ) / 37 ) ) * ( ( ::nWidth - 60 ) / 37 ) + 60
return nil
//-----------------------------------------------------------------//
METHOD LButtonUp( nRow, nCol, nFlags ) CLASS TPickDate
::lMove:=.f.
return nil
//-----------------------------------------------------------------//
METHOD MouseMove( nRow, nCol, nKeyFlags ) CLASS TPickDate
if ::lMove = .t.
::syTemp := Int( ( nCol - 60 ) / ( ( ::nWidth - 60 ) / 37 ) ) * ( ( ::nWidth - 60 ) / 37 ) + 60 + ( ( ::nWidth - 60 ) / 37 )
::Paint()
::refresh()
endif
// ::Say( nRow+10 ,nCol,str( ::nYear, 4 ),,,::oFont, .T., .T. )
return nil
*/
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 48 guests