New Class to SysMonthCal32 window control, now inside fivewin
we can make calendars and config very easy
3 important features:
1) we can set "BOLD" some days, using MCS_DAYSTATE style (see sample bellow)
2) dobleclik is enable over days, the control nos support this feature but is simulate perfectly
3) Launch action (bAction) with ENTER
http://www.sitasoft.net/fivewin/samples/testcal.zip
Code sample
- Code: Select all Expand view
#include "FiveWin.ch"
#include "dtpicker.ch"
#include "calendar.ch"
#include "wcolors.ch"
FUNCTION Main()
LOCAL oWnd, oCal, oDtp1, oDtp2, oDtp3, oDtp4, oCbx
LOCAL oSayClr
LOCAL nColor
LOCAL dDate1, dDate2, dDate3, dDate4, dDate5, dDate6
LOCAL cItemClr
LOCAL lWeekNumbers := .F.
LOCAL lNoTodayCircle := .F.
LOCAL lNoToday := .F.
LOCAL lDayState := .F.
LOCAL oRange3, aRanges2 := { , }
LOCAL oRange4
LOCAL aColorItems := { "MCSC_BACKGROUND " ,;
"MCSC_TEXT " ,;
"MCSC_TITLEBK " ,;
"MCSC_TITLETEXT " ,;
"MCSC_MONTHBK " ,;
"MCSC_TRAILINGTEXT" }
LOCAL oDayOfWeek, cDayOfWeek:="Monday", aDayOfWeek:={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"}
LOCAL oCal2
LOCAL oRange1, aRanges := { , }
LOCAL oRange2
LOCAL oMax, nMax
LOCAL lSunday := .T.
LOCAL lSaturday := .T.
SET DATE TO BRITISH
SET EPOCH TO 1980
dDate1 = Date()
dDate2 = Date()
dDate3 = Date()
dDate4 = Date() + 7
dDate5 = Date()
dDate6 = Date()
DEFINE WINDOW oWnd TITLE "Test Calendar" FROM 0, 0 TO 600, 600 PIXEL
// Start Calendar 1
@ 001, 205 CALENDAR oCal VAR dDate1 OF oWnd PIXEL;
DBLCLICK MsgInfo( oCal:GetDate() );
ON CHANGE oDtp2:cText := oCal:GetDate() SIZE 200, 170;
ACTION( MsgInfo( "ok" ) );
WEEKNUMBER
@ 001, 001 BUTTON "Get Today" OF oWnd PIXEL SIZE 100, 020 ACTION oDtp1:cText := oCal:GetToday()
@ 025, 001 BUTTON "Set Today" OF oWnd PIXEL SIZE 100, 020 ACTION oCal:SetToday( dDate1 )
@ 012, 105 DTPICKER oDtp1 VAR dDate1 OF oWnd PIXEL
@ 050, 001 BUTTON "Get Color" OF oWnd PIXEL SIZE 100, 020 ACTION( oSayClr:SetColor( CLR_BLACK, oCal:GetColors( oCbx:nAt - 1 ) ), oSayClr:Refresh() )
@ 050, 105 BUTTON "Set Color" OF oWnd PIXEL SIZE 100, 020 ACTION( nColor := ChooseColor(), ;
oCal:SetColor( oCbx:nAt - 1, nColor ), ;
oSayClr:SetColor( CLR_BLACK, nColor ),;
oSayClr:Refresh() )
@ 075, 001 COMBOBOX oCbx VAR cItemClr PROMPTS aColorItems PIXEL SIZE 205, 200 OF oWnd
@ 100, 001 SAY oSayClr VAR " " PIXEL SIZE 100, 020 OF oWnd BORDER
@ 125, 001 BUTTON "Get 1 Day Week" OF oWnd SIZE 100, 20 PIXEL ACTION( cDayofWeek := aDayOfWeek[ oCal:GetFirstDayOfWeek() + 1 ], oDayOfWeek:Refresh() )
@ 125, 105 BUTTON "Set 1 Day Week" OF oWnd SIZE 100, 20 PIXEL ACTION( oCal:SetFirstDayOfWeek( oDayOfWeek:FindString( cDayOfWeek ) - 1 ) )
@ 150, 001 COMBOBOX oDayOfWeek VAR cDayofWeek ITEMS aDayOfWeek OF oWnd SIZE 205, 200 PIXEL
@ 175, 001 BUTTON "Get Selected Day" OF oWnd PIXEL SIZE 100, 020 ACTION Msginfo( oCal:GetDate() )
@ 200, 001 BUTTON "Set Selected Day" OF oWnd PIXEL SIZE 100, 020 ACTION oCal:SetDate( dDate2 )
@ 186, 105 DTPICKER oDtp2 VAR dDate2 OF oWnd PIXEL
@ 175, 210 BUTTON "Get Range" OF oWnd PIXEL SIZE 100, 020 ;
ACTION( aRanges2 := oCal:GetRange(), oRange3:Refresh(), oRange4:Refresh() )
@ 175, 310 GET oRange3 VAR aRanges2[ 1 ] OF oWnd SIZE 100, 20 PIXEL
@ 175, 420 GET oRange4 VAR aRanges2[ 2 ] OF oWnd SIZE 100, 20 PIXEL
@ 200, 210 BUTTON "Set Range" OF oWnd PIXEL SIZE 100, 020 ACTION oCal:SetRange( dDate5, dDate6 )
@ 200, 315 DTPICKER oDtp3 VAR dDate5 OF oWnd PIXEL
@ 200, 420 DTPICKER oDtp4 VAR dDate6 OF oWnd PIXEL
@ 001, 410 CHECKBOX oCal:lWeekNumbers PROMPT "Week Numbers" OF oWnd SIZE 100, 20 PIXEL;
ON CHANGE oCal:SetWeekNumbers( oCal:lWeekNumbers )
@ 025, 410 CHECKBOX oCal:lNoTodayCircle PROMPT "No Today Circle" OF oWnd SIZE 100, 20 PIXEL;
ON CHANGE oCal:SetNoTodayCircle( oCal:lNoTodayCircle )
@ 050, 410 CHECKBOX oCal:lNoToday PROMPT "No Today" OF oWnd SIZE 100, 20 PIXEL;
ON CHANGE oCal:SetNoToday( oCal:lNoToday )
oCal:bGotFocus := {|| oCal:SetTitleBk( CLR_YELLOW ) }
oCal:bLostFocus := {|| oCal:SetTitleBk( GetSysColor( COLOR_ACTIVECAPTION ) ) }
// Start Calendar 2
@ 250, 001 CALENDAR oCal2 VAR dDate3, dDate4 OF oWnd PIXEL MULTISELECT DAYSTATE;
DBLCLICK MsgInfo( oCal2:GetDate() ) SIZE 550, 170 COLOR CLR_BLACK, CLR_HRED
@ 230, 001 SAY "MONTHS DISPLAYED: " + StrZero( ocal2:GetVisibleMonths(), 2 ) OF oWnd PIXEL COLOR CLR_WHITE, CLR_BLACK
@ 430, 001 BUTTON "Get Selected Range" OF oWnd SIZE 100, 20 PIXEL ;
ACTION( aRanges := oCal2:GetDateRange(), oRange1:Refresh(), oRange2:Refresh() )
@ 430, 105 GET oRange1 VAR aRanges[ 1 ] OF oWnd SIZE 100, 20 PIXEL
@ 430, 210 GET oRange2 VAR aRanges[ 2 ] OF oWnd SIZE 100, 20 PIXEL
oCal2:bGotFocus := {|| oCal2:SetTitleBk( CLR_YELLOW ) }
oCal2:bLostFocus := {|| oCal2:SetTitleBk( CLR_HRED ) }
nMax = oCal2:GetMaxSelCount()
@ 455, 001 BUTTON "Set Max Selected Day" OF oWnd SIZE 150, 20 PIXEL ;
ACTION( oCal2:SetMaxSelCount( nMax ) )
@ 455, 155 GET oMax VAR nMax OF oWnd SIZE 50, 20 PIXEL SPINNER ;
MIN 1 MAX 60
@ 480, 001 CHECKBOX oCal2:lDayState PROMPT "Day State" OF oWnd SIZE 100, 20 PIXEL;
ON CHANGE( oCal2:SetDayStateStyle( oCal2:lDayState ), ;
If( oCal2:lDayState, ( OnGetState( oCal2, lSunday, lSaturday ), oCal2:SetDayState() ), ) )
@ 505, 001 CHECKBOX lSunday PROMPT "Bold Sunday" OF oWnd SIZE 100, 20 PIXEL
@ 530, 001 CHECKBOX lSaturday PROMPT "Bold Saturday" OF oWnd SIZE 100, 20 PIXEL
OnGetState( oCal2, lSunday, lSaturday )
oCal2:SetDayState()
oCal2:bOnGetState = { | oCal | OnGetState( oCal, lSunday, lSaturday ) }
ACTIVATE WINDOW oWnd
RETURN NIL
Function OnGetState( oCal, lSun, lSat )
LOCAL i, imax, j, jmax, nDay, nDayState, nMonth
LOCAL dStartDate
LOCAL dCurrentDay := oCal:dDate
oCal:GetMonthRange()
dStartDate = oCal:dDate
imax := Len( oCal:aDayState )
nMonth := Month( dStartDate )
FOR i:=1 TO imax
nDayState := 0
FOR j:=1 TO 31
nDay := DoW( dStartDate ) - 2
IF nDay < 0
nDay += 7
ENDIF
IF nDay == 5 .AND. lSat
oCal:SetArrayDayState( i, j )
ENDIF
IF nDay == 6 .AND. lSUN
oCal:SetArrayDayState( i, j )
ENDIF
dStartDate ++
IF Month( dStartDate ) <> nMonth
EXIT
ENDIF
NEXT
nMonth := Month( dStartDate )
NEXT
oCal:SetDate( dCurrentDay )
return nil