Code: Select all | Expand
// C:\FWH\SAMPLES\XBCALEND.PRG By mister Rao.
#include "fivewin.ch"
REQUEST HB_LANG_ESWIN
REQUEST HB_LANG_FR
REQUEST HB_LANG_PT
REQUEST HB_LANG_DEWIN
REQUEST HB_LANG_IT
REQUEST HB_CODEPAGE_PT850
STATIC aCal
FUNCTION Main()
LOCAL aWeeks := Array( 7 )
aCal := Array( 7, 6 )
// hb_langSelect( "EN" )
HB_LANGSELECT( 'PT' ) // Default language is now Portuguese
/*
Mr Rao, if you use this command, it causes an error on the day:
Sábado (SAB) is returned S B. In Portuguese there is no S B but SÁB (Sabádo)
Saturday
HB_SETCODEPAGE( "PT850" )
*/
// AEval( aWeeks, { |u,i| aWeeks[ i ] := Upper( Left( nTocDow( i ), 3 ) ) } )
// XBROWSER aWeeks
ShowCalendar()
RETURN NIL
FUNCTION ShowCalendar()
LOCAL dMth, nMth, nYear, oSaida
LOCAL aMonths := MonthNames()
LOCAL nLang // := 1 // 12/06/2024 - Joao.
LOCAL oDlg, oBrw, oCbxLang, oCbxMth, oGetYr
LOCAL oFont, oBold, cItens, cHeader, cTitle
// dMth := BOM( Date() - 30 ) // 12/06/2024 - Joao.
// It must show the current month and not the previous month.
dMth := BOM( Date() )
nMth := Month( dMth )
nYear := Year( dMth )
FillDates( nMth, nYear )
// 12/06/2024 - Joao.
DEFAULT nLang := FWSetLanguage()
// nLang := 4 // Portuguese
FWSetLanguage( nLang )
SkinButtons()
// 12/06/2024 - Joao.
IF( nLang ) = 4
cItens := { "INGLÊS", "ESPANHOL", "FRANCÊS", "PORTUGUÊS", "ALEMÃO", "ITALIANO" }
cHeader := { "SEMANA", "1", "2", "3", "4", "5" }
cTitle := "CALENDÁRIO"
ELSE
cItens := { "ENGLISH", "SPANISH", "FRENCH", "PORTUGESE", "GERMAN", "ITALIAN" }
cHeader := { "WEEK", "1", "2", "3", "4", "5" }
cTitle := "CALENDAR"
ENDIF
DEFINE FONT oFont NAME "Segoe UI" SIZE 0, - 16
DEFINE FONT oBold NAME "IMPACT" SIZE 0, - 40
DEFINE DIALOG oDlg SIZE 600, 550 PIXEL TRUEPIXEL RESIZABLE FONT oFont ;
TITLE cTitle
// Here it returns wrong. After changing the language
@ 40, 20 COMBOBOX oCbxLang VAR nLang ITEMS cItens ;
SIZE 120, 400 PIXEL OF oDlg ON CHANGE ( ;
hb_langSelect( { "EN", "ES", "FR", "PT", "DE", "IT" }[ nLang ] ), ;
oBrw:Refresh(), oCbxMth:SetItems( aMonths := MonthNames() ) )
@ 40, 200 COMBOBOX oCbxMth VAR nMth ITEMS aMonths ;
SIZE 100, 400 PIXEL OF oDlg ON CHANGE ( ;
FillDates( nMth, nYear ), oBrw:Refresh() )
@ 40, 400 GET oGetYr VAR nYear SIZE 80, 30 PIXEL OF oDlg RIGHT SPINNER ;
ON UP ( FillDates( nMth, ++nYear ), oBrw:Refresh(), oGetYr:Refresh() ) ;
ON DOWN ( FillDates( nMth, --nYear ), oBrw:Refresh(), oGetYr:Refresh() ) ;
VALID ( FillDates( nMth, nYear ), oBrw:Refresh(), .T. )
@ 80, 0 XBROWSE oBrw SIZE 0, 0 PIXEL OF oDlg ;
DATASOURCE aCal ;
COLUMNS {|| Upper( Left( NtoCDow( oBrw:nArrayAt ), 3 ) ) }, 1, 2, 3, 4, 5 ;
HEADERS cHeader ; // "WEEK", "1", "2", "3", "4", "5" ;
LINES NOBORDER
WITH OBJECT oBrw
:nRowHeight := 60
:nWidths := 90
:nStretchCol := 1
:lDisplayZeros := .F.
:lColDividerComplete := .F.
:nDataStrAligns := AL_CENTER
:oDataFonts := oBold
//
:CreateFromCode()
END
@ 001, 500 BUTTONBMP oSaida PROMPT( "&Saida" ) ;
BITMAP "..\bitmaps\16x16\Exit.bmp" TEXTRIGHT SIZE 086, 34 PIXEL ;
FONT oFont OF oDlg ACTION( oDlg:End() ) CANCEL
ACTIVATE DIALOG oDlg CENTERED ON INIT ( oBrw:SetFocus() )
oFont:End()
oBold:End()
RETURN NIL
STATIC FUNCTION FillDates( nMth, nYear )
LOCAL dDate := SToD( Str( nYear, 4 ) + StrZero( nMth, 2 ) + "01" )
LOCAL nDays := LastDayOM( dDate )
LOCAL nDow := DoW( dDate )
LOCAL nRow, nCol, nDay := 1
// this may be revised
IF nDow > 1
AEval( aCal, {| a | a[ 1 ] := 0 }, 1, nDow )
ENDIF
AEval( aCal, {| a | a[ 1 ] := nDay++ }, nDow )
FOR nCol := 2 TO 4
AEval( aCal, {| a | a[ nCol ] := nDay++ } )
NEXT
AEval( aCal, {| a | a[ 5 ] := If( nDay <= nDays, nDay++, 0 ) } )
IF nDay <= nDays
AEval( aCal, {| a | a[ 1 ] := nDay++ }, 1, nDays - nDay + 1 )
ENDIF
RETURN NIL
STATIC FUNCTION MonthNames()
LOCAL aRet := Array( 12 )
AEval( aRet, {| u, i | aRet[ i ] := Upper( NTOCMONTH( i ) ) } )
RETURN aRet
Regards, saludos.