Page 1 of 7

Pickdate

Posted: Thu Jul 24, 2008 5:24 am
by Otto
I am working on a datepicker.
With on LbClick the start position is marked. Then I move the mouse and a chart is paint. The bLButtonUp event sets the end of the selected period.
This is all working.
But I would like to paint the chart in a half transparent way that the selected days shine through.
I use Fillrect for painting the chart.

hBru := CreateSolidBrush( RGB(217,230,246) )
FillRect( oWndPlan:hDc, { 30-18+ (18*(ITemp)) ,buchstart, 30 +(18*(ITemp)), sXTemp}, hBru )

Thanks in advance
Otto

Image

Posted: Thu Jul 24, 2008 6:39 am
by nageswaragunupudi
Mr Otto

Excellant work !!!
I too would like to use your control, if you let me. :)

Posted: Thu Jul 24, 2008 7:42 am
by Otto
Hello NageswaraRao,

I sent you an email.
Regards,
Otto

Posted: Thu Jul 24, 2008 12:10 pm
by nageswaragunupudi
Mr Otto

Thanks for sharing your wonderful code. I sent the modified prg to your email

Posted: Thu Jul 24, 2008 12:25 pm
by Otto
Now with the help of NageswaraRao.
Thank you very much.
Regards,
Otto


Image

Code: Select all

#include "fivewin.ch"

STATIC oWndPlan
STATIC planFont
STATIC sX          := 1
STATIC sY          := 1
STATIC sXTemp      := 0
STATIC sYTemp      := 0
STATIC aPlan       := {}
STATIC startRow    :=0
STATIC startCol    :=0
STATIC startDay    :=""
STATIC oBrush
STATIC lMove       :=.f.
STATIC hBru
STATIC hPen
STATIC hPen1
STATIC hPen3
STATIC aTemp       := {}
STATIC nStartZeile := 0

function main()

   aadd(aTemp,{0,0})                            // 1
   aadd(aTemp,{0,0})                            // 2
   aadd(aTemp,{0,0})                            // 3
   aadd(aTemp,{0,0})                            // 4
   aadd(aTemp,{0,0})                            // 5
   aadd(aTemp,{0,0})                            // 6
   aadd(aTemp,{0,0})                            // 7
   aadd(aTemp,{0,0})                            // 8
   aadd(aTemp,{0,0})                            // 9
   aadd(aTemp,{0,0})                            // 10
   aadd(aTemp,{0,0})                            // 11
   aadd(aTemp,{0,0})                            // 12

   SET DATE GERMAN

   ***

   hBru   := CreateSolidBrush( RGB(217,230,246) )
   hPen   := CreatePen( 0, 1, 12632256 )
   hPen1  := CreatePen( 0, 1, 280 )
   hPen3  := CreatePen( 0, 18,RGB(183,249,185) )//Sonntagsspalte

   DEFINE BRUSH oBrush  COLOR RGB(255,255,255)
   DEFINE FONT planFont NAME "ARIAL" SIZE  0,-11

   ***

   DEFINE WINDOW oWndPlan TITLE "Kalender" ;
      HSCROLL        ;
      FROM 5, 5 TO 24, 98

   oWndPlan:bLClicked  := { |y,x,flags | f_bLClicked(y,x) }
   oWndPlan:bMMoved    := { |y,x,flags | f_MMoved(y,x) }
   oWndPlan:bLButtonUp := { |y,x,flags | f_LButtonUp(y,x) }

   ACTIVATE WINDOW oWndPlan  ON PAINT DrawRowLines()

return nil

func DrawRowLines ()

   LOCAL  I,  nCurrentRows, iZeile
   LOCAL cHeader1     := ""
   LOCAL oSay
   LOCAL hdc
   LOCAL aDays        := {;
      "So","Mo","Di", "Mi", "Do", "Fr", "Sa","So",;
      "Mo","Di", "Mi", "Do", "Fr", "Sa","So",;
      "Mo","Di", "Mi", "Do", "Fr", "Sa","So",;
      "Mo","Di", "Mi", "Do", "Fr", "Sa","So",;
      "Mo","Di", "Mi", "Do", "Fr", "Sa","So","Mo" }

   LOCAL nYear        := YEAR( DATE() )
   LOCAL cYear        := STR( nYear, 4 )
   LOCAL dDate, nStart
   LOCAL lSchaltJahr  := ( DAY( CTOD( "29.02." + cYear ) ) <> 0 )
   LOCAL aDaysInMonth := { 31, IIF( lSchaltJahr, 29, 28 ), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
   LOCAL nColOffSet   := 10
   LOCAL aRect1
   LOCAL IMonate      := 0
   LOCAL ITemp        := 0
   local cTest        := ""
   local nEnde

   FOR IMonate := 1 TO 12

      aadd(aPlan,{"","","", "", "", "", "","",;
         "","", "", "", "", "","",;
         "","", "", "", "", "","",;
         "","", "", "", "", "","",;
         "","", "", "", "", "","","",0,0,0 } )

   NEXT

   aRect1 := { 0,0,500,1000}
   FillRect(oWndPlan:hDc,aRect1,oBrush:hBrush)
   iZeile       := 0
   nCurrentRows := 30

   FOR I := 1 TO  13

      SelectObject( oWndPlan:hDc, hPen )
      IF iZeile = 5
         SelectObject( oWndPlan:hDc, hPen1 )
         iZeile := 0
      ENDIF

      //Lines
      oWndPlan:line (nCurrentRows, 1,nCurrentRows, 726 )
      nCurrentRows := nCurrentRows +  18
      iZeile := iZeile + 1

   NEXT

   nCurrentRows:= 50

   FOR I := 1 TO  38

      SelectObject( oWndPlan:hDc, hPen )
      IF iZeile = 5
         SelectObject( oWndPlan:hDc, hPen1 )
         iZeile := 0
      ENDIF

      oWndPlan:line (10,nColOffSet + nCurrentRows,400, nColOffSet + nCurrentRows )
      nCurrentRows := nCurrentRows +  18
      iZeile := iZeile + 1

   NEXT

   nCurrentRows:= 50

   FOR I := 1 TO len(aDays)

      if aDays[I] = "So"

         //Farbhintergrund Sonntag
         SelectObject( oWndPlan:hDc, hPen3 )

         // Sonntag  erste fette Linie
         oWndPlan:line (0,nColOffSet+   10 + nCurrentRows,400, nColOffSet+  10 + nCurrentRows )

         SelectObject( oWndPlan:hDc, hPen )
         oWndPlan:say( 8, nColOffSet+36+I*18,aDays[I],RGB(255,128,0), RGB(125,236,175),planFont,.T.)

      else
         oWndPlan:say( 8, nColOffSet+36+I*18,aDays[I],RGB(255,128,0),16777215,planFont,.T.)

      endif

      nCurrentRows := nCurrentRows +  18

   NEXT

   nCurrentRows := 12

   FOR I := 1 TO  12

      SelectObject( oWndPlan:hDc, hPen )
      IF iZeile = 5
         SelectObject( oWndPlan:hDc, hPen1 )
         iZeile := 0
      ENDIF

      nCurrentRows := nCurrentRows +  18
      dDate := CTOD( "01." + PADL( ALLTRIM(STR( i, 2 )), 2, "0" ) + "." + cYear )
      nStart := DOW( dDate )
      aPlan[I,38] :=  nStart
      aPlan[I,39] :=  30-18+ (18*( aDaysInMonth[i] + nStart - 1 )) //col begin of month
      aPlan[I,40] :=  nStart + aDaysInMonth[i]  //col end of month

      FOR iZeile := nStart TO aDaysInMonth[i] + nStart - 1
         aPlan[I,iZeile] =    ( PADL( ALLTRIM(STR( (iZeile-nStart+1), 2 )), 2, "0" )+ "." + PADL( ALLTRIM(STR( (I), 2 )), 2, "0" ) + "." + cYear )
      NEXT

      cHeader1 :=      OemToAnsi( CMONTH( dDate ) ) //Monate
      oWndPlan:say( nCurrentRows+1, 2, cHeader1,RGB(63,63,63),16777215,planFont,.T.)

   NEXT

   IF (sy > 0 .AND. sy < 13)  .AND.  (sx > 0 .AND. sx < 38)


      IF lMove = .t.
         IZeile := INT((syTemp-30)/18 ) + 1
         aTemp[IZeile,1]:=10

         FOR ITemp := IZeile+1 TO 12
            aTemp[ITemp,1]:=0
         NEXT

         FOR ITemp := 1 TO 12

            if aTemp[ITemp,1] > 0
               if sXTemp > aPlan[ITemp,39] + aPlan[ITemp,38]*18
                  sXTemp := aPlan[ITemp,39] + aPlan[ITemp,38]*18
               endif

               IF 30-18+ (18*(ITemp)) >= startCol  .AND. ;
                  .NOT.  (30-18+ (18*(ITemp)) = startCol  .AND. ;
                  startRow > sXTemp)

                  FillRect( oWndPlan:hDc, { 30-18+ (18*(ITemp)),startRow, 30 +(18*(ITemp)), sXTemp}, hBru )

                  IF ITemp > nStartZeile
                     FillRect( oWndPlan:hDc, { 30-18+ (18*(ITemp-1)),startRow, 30 +(18*(ITemp-1)), (30 +( 13 + 18*(aPlan[ITemp-1,40])))   }, hBru )
                     FillRect( oWndPlan:hDc, { 30-18+ (18*(ITemp)),  30 + 13 + (18*(aPlan[ITemp,38])), 30 +(18*(ITemp)), sXTemp}, hBru )
                  ENDIF

               else
                  FillRect( oWndPlan:hDc, {startCol,startRow,startCol+18,startRow+18}, hBru )
               ENDIF
            endif
         NEXT
      ENDIF
   ENDIF

   nCurrentRows := 12

   FOR I := 1 TO  12

      SelectObject( oWndPlan:hDc, hPen )
      IF iZeile = 5
         SelectObject( oWndPlan:hDc, hPen1 )
         iZeile := 0
      ENDIF

      nCurrentRows := nCurrentRows +  18
      dDate := CTOD( "01." + PADL( ALLTRIM(STR( i, 2 )), 2, "0" ) + "." + cYear )
      nStart := DOW( dDate )

      aPlan[I,38] :=  nStart
      aPlan[I,39] :=  30-18+ (18*( aDaysInMonth[i] + nStart - 1 )) //col begin of month
      aPlan[I,40] :=  nStart + aDaysInMonth[i]  //col end of month

      FOR iZeile := nStart TO aDaysInMonth[i] + nStart - 1

         cHeader1 :=    ALLTRIM(str(iZeile-nStart+1)) //Tage
         if aDays[iZeile] = "So"
            oWndPlan:say( nCurrentRows+3,36 + nColOffSet + (iZeile)  *18, ;
               cHeader1, RGB(63,63,63),RGB(125,236,175),planFont,.T.,.T.)
         else
            oWndPlan:say( nCurrentRows+3,36 + nColOffSet + (iZeile)  *18, ;
               cHeader1, RGB(63,63,63),16777215,planFont,.T., .T.)
         ENDIF
      NEXT
   NEXT

   IF (sy > 0 .AND. sy < 13)  .AND.  (sx > 0 .AND. sx < 38)
      oWndPlan:say(syTemp+20, sxTemp-20,  aPlan[sy, sx] + " # "+str(ctod(aPlan[sy, sx])-ctod(startDay)+ 1), RGB(63,63,63), RGB(125,236,175), planFont, .T. )
   endif

return nil

func f_LButtonUp(y,x)

   msginfo(startDay + " -- " + aPlan[sy, sx] + "    Tage: " + str( ctod(aPlan[sy, sx])-ctod(startDay)  +1   ))
   lMove:=.f.

return nil

func  f_MMoved(y,x)

   IF sy <>  (INT((y-30)/18 ) + 1) .OR. sy <> (INT( (x-50-10)/18 ) + 1 )
      sy := INT((y-30)/18 ) + 1
      sx := INT((x-50-10)/18 ) + 1

      IF y < 30
         sy := 0
         y  := 0
      ENDIF

      syTemp := y
      sxTemp :=   59 +      sx * 18

      oWndPlan:refresh()

   ENDIF

return nil

func f_bLClicked(y,x)

   local ITemp:=0

   sy := INT((y-30)/18 ) + 1
   sx := INT((x-50-10)/18 ) + 1
   startDay := aPlan[sy, sx]
   nStartZeile := sy
   startRow := INT((x - 30)/18)*18   + 18 + 7
   startCol := (INT((y-30)/18 ))*18 + 30

   FOR ITemp := 1 TO 12
      aTemp[ITemp,1]:=0
   NEXT

   FillRect( oWndPlan:hDc, {startCol,startRow,startCol+18,startRow+18}, hBru )
   oWndPlan:refresh()

   lMove:=.t.

return nil

Posted: Thu Jul 24, 2008 4:32 pm
by Silvio
Otto ,
have you made with listbox or sbrowse or xbrowse ?

Posted: Thu Jul 24, 2008 4:59 pm
by Otto
Silvio,
I inserted the source.
Regards,
Otto

Posted: Fri Jul 25, 2008 1:40 am
by RAMESHBABU
Mr.Otto

Thank you very much.

- Ramesh Babu P

Posted: Fri Jul 25, 2008 5:00 am
by Rochinha
Otto

I make a little changes in your control to use Horizontal Scroll:

Code: Select all

#include "fivewin.ch" 

STATIC oWndPlan 
STATIC planFont 
STATIC sX          := 1 
STATIC sY          := 1 
STATIC sXTemp      := 0 
STATIC sYTemp      := 0 
STATIC aPlan       := {} 
STATIC startRow    :=0 
STATIC startCol    :=0 
STATIC startDay    :="" 
STATIC oBrush 
STATIC lMove       :=.f. 
STATIC hBru 
STATIC hPen 
STATIC hPen1 
STATIC hPen3 
STATIC aTemp       := {} 
STATIC nStartZeile := 0 

function main() 

   /* ********** added by rochinha ********** */
   PUBLIC nYear       := YEAR( DATE() ) 
   /* ********** added by rochinha ********** */

   aadd(aTemp,{0,0})                            // 1 
   aadd(aTemp,{0,0})                            // 2 
   aadd(aTemp,{0,0})                            // 3 
   aadd(aTemp,{0,0})                            // 4 
   aadd(aTemp,{0,0})                            // 5 
   aadd(aTemp,{0,0})                            // 6 
   aadd(aTemp,{0,0})                            // 7 
   aadd(aTemp,{0,0})                            // 8 
   aadd(aTemp,{0,0})                            // 9 
   aadd(aTemp,{0,0})                            // 10 
   aadd(aTemp,{0,0})                            // 11 
   aadd(aTemp,{0,0})                            // 12 

   SET DATE GERMAN 

   *** 

   hBru   := CreateSolidBrush( RGB(217,230,246) ) 
   hPen   := CreatePen( 0, 1, 12632256 ) 
   hPen1  := CreatePen( 0, 1, 280 ) 
   hPen3  := CreatePen( 0, 18,RGB(183,249,185) )//Sonntagsspalte 

   DEFINE BRUSH oBrush  COLOR RGB(255,255,255) 
   DEFINE FONT planFont NAME "ARIAL" SIZE  0,-11 

   *** 

   DEFINE WINDOW oWndPlan TITLE "Kalender" ; 
      HSCROLL        ; 
      FROM 5, 5 TO 24, 98 

   oWndPlan:bLClicked  := { |y,x,flags | f_bLClicked(y,x) } 
   oWndPlan:bMMoved    := { |y,x,flags | f_MMoved(y,x) } 
   oWndPlan:bLButtonUp := { |y,x,flags | f_LButtonUp(y,x) } 

   /* ********** added by rochinha ********** */
   oWndPlan:cTitle     := "Kalender [ " + str(nYear,4) + " ]" 
   /* ********** added by rochinha ********** */

   /* ********** added by rochinha ********** */
   oWndPlan:oHScroll:bGoUp   := {|| PreviousYear() }
   oWndPlan:oHScroll:bGoDown := {|| NextYear() }
   /* ********** added by rochinha ********** */

   ACTIVATE WINDOW oWndPlan  ON PAINT DrawRowLines() 

return nil 

func PreviousYear() /* ********** added by rochinha ********** */
   nYear := nYear - 1
   DrawRowLines() 
   oWndPlan:refresh() 
   oWndPlan:cTitle := "Kalender [ " + str(nYear,4) + " ]" 
   return .t.

func NextYear()     /* ********** added by rochinha ********** */
   nYear := nYear + 1
   DrawRowLines() 
   oWndPlan:refresh() 
   oWndPlan:cTitle := "Kalender [ " + str(nYear,4) + " ]" 
   return .t.

func DrawRowLines ()

   LOCAL  I,  nCurrentRows, iZeile 
   LOCAL cHeader1     := "" 
   LOCAL oSay 
   LOCAL hdc 
   LOCAL aDays        := {; 
      "So","Mo","Di", "Mi", "Do", "Fr", "Sa","So",; 
      "Mo","Di", "Mi", "Do", "Fr", "Sa","So",; 
      "Mo","Di", "Mi", "Do", "Fr", "Sa","So",; 
      "Mo","Di", "Mi", "Do", "Fr", "Sa","So",; 
      "Mo","Di", "Mi", "Do", "Fr", "Sa","So","Mo" } 

   /* blocked by rochinha 
   LOCAL nYear        := YEAR( DATE() ) */
   LOCAL cYear        := STR( nYear, 4 ) 
   LOCAL dDate, nStart 
   LOCAL lSchaltJahr  := ( DAY( CTOD( "29.02." + cYear ) ) <> 0 ) 
   LOCAL aDaysInMonth := { 31, IIF( lSchaltJahr, 29, 28 ), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } 
   LOCAL nColOffSet   := 10 
   LOCAL aRect1 
   LOCAL IMonate      := 0 
   LOCAL ITemp        := 0 
   local cTest        := "" 
   local nEnde 

   FOR IMonate := 1 TO 12 

      aadd(aPlan,{"","","", "", "", "", "","",; 
         "","", "", "", "", "","",; 
         "","", "", "", "", "","",; 
         "","", "", "", "", "","",; 
         "","", "", "", "", "","","",0,0,0 } ) 

   NEXT 

   aRect1 := { 0,0,500,1000} 
   FillRect(oWndPlan:hDc,aRect1,oBrush:hBrush) 
   iZeile       := 0 
   nCurrentRows := 30 

   FOR I := 1 TO  13 

      SelectObject( oWndPlan:hDc, hPen ) 
      IF iZeile = 5 
         SelectObject( oWndPlan:hDc, hPen1 ) 
         iZeile := 0 
      ENDIF 

      //Lines 
      oWndPlan:line (nCurrentRows, 1,nCurrentRows, 726 ) 
      nCurrentRows := nCurrentRows +  18 
      iZeile := iZeile + 1 

   NEXT 

   nCurrentRows:= 50 

   FOR I := 1 TO  38 

      SelectObject( oWndPlan:hDc, hPen ) 
      IF iZeile = 5 
         SelectObject( oWndPlan:hDc, hPen1 ) 
         iZeile := 0 
      ENDIF 

      oWndPlan:line (10,nColOffSet + nCurrentRows,400, nColOffSet + nCurrentRows ) 
      nCurrentRows := nCurrentRows +  18 
      iZeile := iZeile + 1 

   NEXT 

   nCurrentRows:= 50 

   FOR I := 1 TO len(aDays) 

      if aDays[I] = "So" 

         //Farbhintergrund Sonntag 
         SelectObject( oWndPlan:hDc, hPen3 ) 

         // Sonntag  erste fette Linie 
         oWndPlan:line (0,nColOffSet+   10 + nCurrentRows,400, nColOffSet+  10 + nCurrentRows ) 

         SelectObject( oWndPlan:hDc, hPen ) 
         oWndPlan:say( 8, nColOffSet+36+I*18,aDays[I],RGB(255,128,0), RGB(125,236,175),planFont,.T.) 

      else 
         oWndPlan:say( 8, nColOffSet+36+I*18,aDays[I],RGB(255,128,0),16777215,planFont,.T.) 

      endif 

      nCurrentRows := nCurrentRows +  18 

   NEXT 

   nCurrentRows := 12 

   FOR I := 1 TO  12 

      SelectObject( oWndPlan:hDc, hPen ) 
      IF iZeile = 5 
         SelectObject( oWndPlan:hDc, hPen1 ) 
         iZeile := 0 
      ENDIF 

      nCurrentRows := nCurrentRows +  18 
      dDate := CTOD( "01." + PADL( ALLTRIM(STR( i, 2 )), 2, "0" ) + "." + cYear ) 
      nStart := DOW( dDate ) 
      aPlan[I,38] :=  nStart 
      aPlan[I,39] :=  30-18+ (18*( aDaysInMonth[i] + nStart - 1 )) //col begin of month 
      aPlan[I,40] :=  nStart + aDaysInMonth[i]  //col end of month 

      FOR iZeile := nStart TO aDaysInMonth[i] + nStart - 1 
         aPlan[I,iZeile] =    ( PADL( ALLTRIM(STR( (iZeile-nStart+1), 2 )), 2, "0" )+ "." + PADL( ALLTRIM(STR( (I), 2 )), 2, "0" ) + "." + cYear ) 
      NEXT 

      cHeader1 :=      OemToAnsi( CMONTH( dDate ) ) //Monate 
      oWndPlan:say( nCurrentRows+1, 2, cHeader1,RGB(63,63,63),16777215,planFont,.T.) 

   NEXT 

   IF (sy > 0 .AND. sy < 13)  .AND.  (sx > 0 .AND. sx < 38) 


      IF lMove = .t. 
         IZeile := INT((syTemp-30)/18 ) + 1 
         aTemp[IZeile,1]:=10 

         FOR ITemp := IZeile+1 TO 12 
            aTemp[ITemp,1]:=0 
         NEXT 

         FOR ITemp := 1 TO 12 

            if aTemp[ITemp,1] > 0 
               if sXTemp > aPlan[ITemp,39] + aPlan[ITemp,38]*18 
                  sXTemp := aPlan[ITemp,39] + aPlan[ITemp,38]*18 
               endif 

               IF 30-18+ (18*(ITemp)) >= startCol  .AND. ; 
                  .NOT.  (30-18+ (18*(ITemp)) = startCol  .AND. ; 
                  startRow > sXTemp) 

                  FillRect( oWndPlan:hDc, { 30-18+ (18*(ITemp)),startRow, 30 +(18*(ITemp)), sXTemp}, hBru ) 

                  IF ITemp > nStartZeile 
                     FillRect( oWndPlan:hDc, { 30-18+ (18*(ITemp-1)),startRow, 30 +(18*(ITemp-1)), (30 +( 13 + 18*(aPlan[ITemp-1,40])))   }, hBru ) 
                     FillRect( oWndPlan:hDc, { 30-18+ (18*(ITemp)),  30 + 13 + (18*(aPlan[ITemp,38])), 30 +(18*(ITemp)), sXTemp}, hBru ) 
                  ENDIF 

               else 
                  FillRect( oWndPlan:hDc, {startCol,startRow,startCol+18,startRow+18}, hBru ) 
               ENDIF 
            endif 
         NEXT 
      ENDIF 
   ENDIF 

   nCurrentRows := 12 

   FOR I := 1 TO  12 

      SelectObject( oWndPlan:hDc, hPen ) 
      IF iZeile = 5 
         SelectObject( oWndPlan:hDc, hPen1 ) 
         iZeile := 0 
      ENDIF 

      nCurrentRows := nCurrentRows +  18 
      dDate := CTOD( "01." + PADL( ALLTRIM(STR( i, 2 )), 2, "0" ) + "." + cYear ) 
      nStart := DOW( dDate ) 

      aPlan[I,38] :=  nStart 
      aPlan[I,39] :=  30-18+ (18*( aDaysInMonth[i] + nStart - 1 )) //col begin of month 
      aPlan[I,40] :=  nStart + aDaysInMonth[i]  //col end of month 

      FOR iZeile := nStart TO aDaysInMonth[i] + nStart - 1 

         cHeader1 :=    ALLTRIM(str(iZeile-nStart+1)) //Tage 
         if aDays[iZeile] = "So" 
            oWndPlan:say( nCurrentRows+3,36 + nColOffSet + (iZeile)  *18, ; 
               cHeader1, RGB(63,63,63),RGB(125,236,175),planFont,.T.,.T.) 
         else 
            oWndPlan:say( nCurrentRows+3,36 + nColOffSet + (iZeile)  *18, ; 
               cHeader1, RGB(63,63,63),16777215,planFont,.T., .T.) 
         ENDIF 
      NEXT 
   NEXT 

   IF (sy > 0 .AND. sy < 13)  .AND.  (sx > 0 .AND. sx < 38) 
      oWndPlan:say(syTemp+20, sxTemp-20,  aPlan[sy, sx] + " # "+str(ctod(aPlan[sy, sx])-ctod(startDay)+ 1), RGB(63,63,63), RGB(125,236,175), planFont, .T. ) 
   endif 

return nil 

func f_LButtonUp(y,x) 

   msginfo(startDay + " -- " + aPlan[sy, sx] + "    Tage: " + str( ctod(aPlan[sy, sx])-ctod(startDay)  +1   )) 
   lMove:=.f. 

return nil 

func  f_MMoved(y,x) 

   IF sy <>  (INT((y-30)/18 ) + 1) .OR. sy <> (INT( (x-50-10)/18 ) + 1 ) 
      sy := INT((y-30)/18 ) + 1 
      sx := INT((x-50-10)/18 ) + 1 

      IF y < 30 
         sy := 0 
         y  := 0 
      ENDIF 

      syTemp := y 
      sxTemp :=   59 +      sx * 18 

      oWndPlan:refresh() 

   ENDIF 

return nil 

func f_bLClicked(y,x) 

   local ITemp:=0 

   sy := INT((y-30)/18 ) + 1 
   sx := INT((x-50-10)/18 ) + 1 
   startDay := aPlan[sy, sx] 
   nStartZeile := sy 
   startRow := INT((x - 30)/18)*18   + 18 + 7 
   startCol := (INT((y-30)/18 ))*18 + 30 

   FOR ITemp := 1 TO 12 
      aTemp[ITemp,1]:=0 
   NEXT 

   FillRect( oWndPlan:hDc, {startCol,startRow,startCol+18,startRow+18}, hBru ) 
   oWndPlan:refresh() 

   lMove:=.t. 

return nil 

Posted: Fri Jul 25, 2008 6:22 am
by quique
My apport over Rochinha changes (it removes warnings of variable to the moment to compile and error messages upon giving click)

Code: Select all

#include "fivewin.ch"

STATIC oWndPlan
STATIC planFont
STATIC sX          := 1
STATIC sY          := 1
STATIC sXTemp      := 0
STATIC sYTemp      := 0
STATIC aPlan       := {}
STATIC startRow    :=0
STATIC startCol    :=0
STATIC startDay    :=""
STATIC oBrush
STATIC lMove       :=.f.
STATIC hBru
STATIC hPen
STATIC hPen1
STATIC hPen3
STATIC aTemp       := {}
STATIC nStartZeile := 0
   /* ********** added by rochinha, modify by Quique ********** */
STATIC nYear
   /* ********** added by rochinha, modify by Quique ********** */

function main()
   /* ********** added by rochinha, modify by Quique ********** */
   nYear       := YEAR( DATE() )
   /* ********** added by rochinha, modify by Quique ********** */

   aadd(aTemp,{0,0})                            // 1
   aadd(aTemp,{0,0})                            // 2
   aadd(aTemp,{0,0})                            // 3
   aadd(aTemp,{0,0})                            // 4
   aadd(aTemp,{0,0})                            // 5
   aadd(aTemp,{0,0})                            // 6
   aadd(aTemp,{0,0})                            // 7
   aadd(aTemp,{0,0})                            // 8
   aadd(aTemp,{0,0})                            // 9
   aadd(aTemp,{0,0})                            // 10
   aadd(aTemp,{0,0})                            // 11
   aadd(aTemp,{0,0})                            // 12

   SET DATE GERMAN

   ***

   hBru   := CreateSolidBrush( RGB(217,230,246) )
   hPen   := CreatePen( 0, 1, 12632256 )
   hPen1  := CreatePen( 0, 1, 280 )
   hPen3  := CreatePen( 0, 18,RGB(183,249,185) )//Sonntagsspalte

   DEFINE BRUSH oBrush  COLOR RGB(255,255,255)
   DEFINE FONT planFont NAME "ARIAL" SIZE  0,-11

   ***

   DEFINE WINDOW oWndPlan TITLE "Kalender" ;
      HSCROLL        ;
      FROM 5, 5 TO 24, 98

   oWndPlan:bLClicked  := { |y,x,flags | f_bLClicked(y,x) }
   oWndPlan:bMMoved    := { |y,x,flags | f_MMoved(y,x) }
   oWndPlan:bLButtonUp := { |y,x,flags | f_LButtonUp(y,x) }

   /* ********** added by rochinha ********** */
   oWndPlan:cTitle     := "Kalender [ " + str(nYear,4) + " ]"
   /* ********** added by rochinha ********** */

   /* ********** added by rochinha ********** */
   oWndPlan:oHScroll:bGoUp   := {|| PreviousYear() }
   oWndPlan:oHScroll:bGoDown := {|| NextYear() }
   /* ********** added by rochinha ********** */

   ACTIVATE WINDOW oWndPlan  ON PAINT DrawRowLines()

return nil

func PreviousYear() /* ********** added by rochinha ********** */
   nYear := nYear - 1
   DrawRowLines()
   oWndPlan:refresh()
   oWndPlan:cTitle := "Kalender [ " + str(nYear,4) + " ]"
   return .t.

func NextYear()     /* ********** added by rochinha ********** */
   nYear := nYear + 1
   DrawRowLines()
   oWndPlan:refresh()
   oWndPlan:cTitle := "Kalender [ " + str(nYear,4) + " ]"
   return .t.

func DrawRowLines ()

   LOCAL  I,  nCurrentRows, iZeile
   LOCAL cHeader1     := ""
   LOCAL oSay
   LOCAL hdc
   LOCAL aDays        := {;
      "So","Mo","Di", "Mi", "Do", "Fr", "Sa","So",;
      "Mo","Di", "Mi", "Do", "Fr", "Sa","So",;
      "Mo","Di", "Mi", "Do", "Fr", "Sa","So",;
      "Mo","Di", "Mi", "Do", "Fr", "Sa","So",;
      "Mo","Di", "Mi", "Do", "Fr", "Sa","So","Mo" }

   /* blocked by rochinha
   LOCAL nYear        := YEAR( DATE() ) */
   LOCAL cYear        := STR( nYear, 4 )
   LOCAL dDate, nStart
   LOCAL lSchaltJahr  := ( DAY( CTOD( "29.02." + cYear ) ) <> 0 )
   LOCAL aDaysInMonth := { 31, IIF( lSchaltJahr, 29, 28 ), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
   LOCAL nColOffSet   := 10
   LOCAL aRect1
   LOCAL IMonate      := 0
   LOCAL ITemp        := 0
   local cTest        := ""
   local nEnde

   FOR IMonate := 1 TO 12

      aadd(aPlan,{"","","", "", "", "", "","",;
         "","", "", "", "", "","",;
         "","", "", "", "", "","",;
         "","", "", "", "", "","",;
         "","", "", "", "", "","","",0,0,0 } )

   NEXT

   aRect1 := { 0,0,500,1000}
   FillRect(oWndPlan:hDc,aRect1,oBrush:hBrush)
   iZeile       := 0
   nCurrentRows := 30

   FOR I := 1 TO  13

      SelectObject( oWndPlan:hDc, hPen )
      IF iZeile = 5
         SelectObject( oWndPlan:hDc, hPen1 )
         iZeile := 0
      ENDIF

      //Lines
      oWndPlan:line (nCurrentRows, 1,nCurrentRows, 726 )
      nCurrentRows := nCurrentRows +  18
      iZeile := iZeile + 1

   NEXT

   nCurrentRows:= 50

   FOR I := 1 TO  38

      SelectObject( oWndPlan:hDc, hPen )
      IF iZeile = 5
         SelectObject( oWndPlan:hDc, hPen1 )
         iZeile := 0
      ENDIF

      oWndPlan:line (10,nColOffSet + nCurrentRows,400, nColOffSet + nCurrentRows )
      nCurrentRows := nCurrentRows +  18
      iZeile := iZeile + 1

   NEXT

   nCurrentRows:= 50

   FOR I := 1 TO len(aDays)

      if aDays[I] = "So"

         //Farbhintergrund Sonntag
         SelectObject( oWndPlan:hDc, hPen3 )

         // Sonntag  erste fette Linie
         oWndPlan:line (0,nColOffSet+   10 + nCurrentRows,400, nColOffSet+  10 + nCurrentRows )

         SelectObject( oWndPlan:hDc, hPen )
         oWndPlan:say( 8, nColOffSet+36+I*18,aDays[I],RGB(255,128,0), RGB(125,236,175),planFont,.T.)

      else
         oWndPlan:say( 8, nColOffSet+36+I*18,aDays[I],RGB(255,128,0),16777215,planFont,.T.)

      endif

      nCurrentRows := nCurrentRows +  18

   NEXT

   nCurrentRows := 12

   FOR I := 1 TO  12

      SelectObject( oWndPlan:hDc, hPen )
      IF iZeile = 5
         SelectObject( oWndPlan:hDc, hPen1 )
         iZeile := 0
      ENDIF

      nCurrentRows := nCurrentRows +  18
      dDate := CTOD( "01." + PADL( ALLTRIM(STR( i, 2 )), 2, "0" ) + "." + cYear )
      nStart := DOW( dDate )
      aPlan[I,38] :=  nStart
      aPlan[I,39] :=  30-18+ (18*( aDaysInMonth[i] + nStart - 1 )) //col begin of month
      aPlan[I,40] :=  nStart + aDaysInMonth[i]  //col end of month

      FOR iZeile := nStart TO aDaysInMonth[i] + nStart - 1
         aPlan[I,iZeile] =    ( PADL( ALLTRIM(STR( (iZeile-nStart+1), 2 )), 2, "0" )+ "." + PADL( ALLTRIM(STR( (I), 2 )), 2, "0" ) + "." + cYear )
      NEXT

      cHeader1 :=      OemToAnsi( CMONTH( dDate ) ) //Monate
      oWndPlan:say( nCurrentRows+1, 2, cHeader1,RGB(63,63,63),16777215,planFont,.T.)

   NEXT

   IF (sy > 0 .AND. sy < 13)  .AND.  (sx > 0 .AND. sx < 38)


      IF lMove = .t.
         IZeile := INT((syTemp-30)/18 ) + 1
         aTemp[IZeile,1]:=10

         FOR ITemp := IZeile+1 TO 12
            aTemp[ITemp,1]:=0
         NEXT

         FOR ITemp := 1 TO 12

            if aTemp[ITemp,1] > 0
               if sXTemp > aPlan[ITemp,39] + aPlan[ITemp,38]*18
                  sXTemp := aPlan[ITemp,39] + aPlan[ITemp,38]*18
               endif

               IF 30-18+ (18*(ITemp)) >= startCol  .AND. ;
                  .NOT.  (30-18+ (18*(ITemp)) = startCol  .AND. ;
                  startRow > sXTemp)

                  FillRect( oWndPlan:hDc, { 30-18+ (18*(ITemp)),startRow, 30 +(18*(ITemp)), sXTemp}, hBru )

                  IF ITemp > nStartZeile
                     FillRect( oWndPlan:hDc, { 30-18+ (18*(ITemp-1)),startRow, 30 +(18*(ITemp-1)), (30 +( 13 + 18*(aPlan[ITemp-1,40])))   }, hBru )
                     FillRect( oWndPlan:hDc, { 30-18+ (18*(ITemp)),  30 + 13 + (18*(aPlan[ITemp,38])), 30 +(18*(ITemp)), sXTemp}, hBru )
                  ENDIF

               else
                  FillRect( oWndPlan:hDc, {startCol,startRow,startCol+18,startRow+18}, hBru )
               ENDIF
            endif
         NEXT
      ENDIF
   ENDIF

   nCurrentRows := 12

   FOR I := 1 TO  12

      SelectObject( oWndPlan:hDc, hPen )
      IF iZeile = 5
         SelectObject( oWndPlan:hDc, hPen1 )
         iZeile := 0
      ENDIF

      nCurrentRows := nCurrentRows +  18
      dDate := CTOD( "01." + PADL( ALLTRIM(STR( i, 2 )), 2, "0" ) + "." + cYear )
      nStart := DOW( dDate )

      aPlan[I,38] :=  nStart
      aPlan[I,39] :=  30-18+ (18*( aDaysInMonth[i] + nStart - 1 )) //col begin of month
      aPlan[I,40] :=  nStart + aDaysInMonth[i]  //col end of month

      FOR iZeile := nStart TO aDaysInMonth[i] + nStart - 1

         cHeader1 :=    ALLTRIM(str(iZeile-nStart+1)) //Tage
         if aDays[iZeile] = "So"
            oWndPlan:say( nCurrentRows+3,36 + nColOffSet + (iZeile)  *18, ;
               cHeader1, RGB(63,63,63),RGB(125,236,175),planFont,.T.,.T.)
         else
            oWndPlan:say( nCurrentRows+3,36 + nColOffSet + (iZeile)  *18, ;
               cHeader1, RGB(63,63,63),16777215,planFont,.T., .T.)
         ENDIF
      NEXT
   NEXT

   IF (sy > 0 .AND. sy < 13)  .AND.  (sx > 0 .AND. sx < 38)
      oWndPlan:say(syTemp+20, sxTemp-20,  aPlan[sy, sx] + " # "+str(ctod(aPlan[sy, sx])-ctod(startDay)+ 1), RGB(63,63,63), RGB(125,236,175), planFont, .T. )
   endif

return nil

func f_LButtonUp(y,x)

   IF sx > 0   // Quique
      msginfo(startDay + " -- " + aPlan[sy, sx] + "    Tage: " + str( ctod(aPlan[sy, sx])-ctod(startDay)  +1   ))
   ENDIF
   lMove:=.f.

return nil

func  f_MMoved(y,x)

   IF sy <>  (INT((y-30)/18 ) + 1) .OR. sy <> (INT( (x-50-10)/18 ) + 1 )
      sy := INT((y-30)/18 ) + 1
      sx := INT((x-50-10)/18 ) + 1

      IF y < 30
         sy := 0
         y  := 0
      ENDIF

      syTemp := y
      sxTemp :=   59 +      sx * 18

      oWndPlan:refresh()

   ENDIF

return nil

func f_bLClicked(y,x)

   local ITemp:=0

   sy := INT((y-30)/18 ) + 1
   sx := INT((x-50-10)/18 ) + 1
   IF sx > 0   // Quique
      startDay := aPlan[sy, sx]
      nStartZeile := sy
      startRow := INT((x - 30)/18)*18   + 18 + 7
      startCol := (INT((y-30)/18 ))*18 + 30

      FOR ITemp := 1 TO 12
         aTemp[ITemp,1]:=0
      NEXT

      FillRect( oWndPlan:hDc, {startCol,startRow,startCol+18,startRow+18}, hBru )
      oWndPlan:refresh()

      lMove:=.t.
   ENDIF

return nil

Posted: Fri Jul 25, 2008 6:44 am
by Otto
Hello Rochinha, hello quique,

Thank you for your feedback.
The scrolling is a good idea but I think we should implement it vertical.
and maybe also month by month.
This way I think it would be more intuitive.

What do you think?
Regards,
Otto

Posted: Fri Jul 25, 2008 6:56 am
by Carles
Otto,

IF at begin of func DrawRowLines(), you write

Code: Select all

local aInfo := oWndPlan:DispBegin()
and the end func you put

Code: Select all

oWndPlan:DispEnd( aInfo )
maybe is better... :wink:

Congratulations...

Posted: Fri Jul 25, 2008 8:25 am
by Otto
Quique, Rochinha, NageswaraRao, Carles

I saw that I had a mistake in naming the variables. X was y and vice versa. I changed the code.

Please lets go ahead with this.

Carles:
What is local aInfo := oWndPlan:DispBegin()
exactly doing?

Regards,
Otto

PS: Could you please send me your email addresses.
I would like to share my snipkeeper code with you, too.
datron&aon.at (& =@)


Code: Select all

#include "fivewin.ch"

STATIC oWndPlan
STATIC planFont
STATIC sy          := 1
STATIC sx          := 1
STATIC syTemp      := 0
STATIC sxTemp      := 0
STATIC aPlan       := {}
STATIC ClickCol    :=0
STATIC ClickRow    :=0
STATIC startDay    :=""
STATIC oBrush
STATIC lMove       :=.f.
STATIC hBru
STATIC hPen
STATIC hPen1
STATIC hPen3
STATIC aTemp       := {}
STATIC nStartZeile := 0

   /* ********** added by rochinha, modify by Quique ********** */
STATIC nYear
   /* ********** added by rochinha, modify by Quique ********** */

function main()
   /* ********** added by rochinha, modify by Quique ********** */
   nYear       := YEAR( DATE() )
   /* ********** added by rochinha, modify by Quique ********** */

   aadd(aTemp,{0,0})                            // 1
   aadd(aTemp,{0,0})                            // 2
   aadd(aTemp,{0,0})                            // 3
   aadd(aTemp,{0,0})                            // 4
   aadd(aTemp,{0,0})                            // 5
   aadd(aTemp,{0,0})                            // 6
   aadd(aTemp,{0,0})                            // 7
   aadd(aTemp,{0,0})                            // 8
   aadd(aTemp,{0,0})                            // 9
   aadd(aTemp,{0,0})                            // 10
   aadd(aTemp,{0,0})                            // 11
   aadd(aTemp,{0,0})                            // 12

   SET DATE GERMAN

   ***

   hBru   := CreateSolidBrush( RGB(217,230,246) )
   hPen   := CreatePen( 0, 1, 12632256 )
   hPen1  := CreatePen( 0, 1, 280 )
   hPen3  := CreatePen( 0, 18,RGB(183,249,185) )//Sonntagsspalte

   DEFINE BRUSH oBrush  COLOR RGB(255,255,255)
   DEFINE FONT planFont NAME "ARIAL" SIZE  0,-11

   ***

   DEFINE WINDOW oWndPlan TITLE "Kalender" ;
      HSCROLL        ;
      FROM 5, 5 TO 24, 98

   oWndPlan:bLClicked  := { |x,y,flags | f_bLClicked(x,y) }
   oWndPlan:bMMoved    := { |x,y,flags | f_MMoved(x,y) }
   oWndPlan:bLButtonUp := { |x,y,flags | f_LButtonUp(x,y) }

   /* ********** added by rochinha ********** */
   oWndPlan:cTitle     := "Kalender [ " + str(nYear,4) + " ]"
   /* ********** added by rochinha ********** */

   /* ********** added by rochinha ********** */
   oWndPlan:oHScroll:bGoUp   := {|| PreviousYear() }
   oWndPlan:oHScroll:bGoDown := {|| NextYear() }
   /* ********** added by rochinha ********** */

   ACTIVATE WINDOW oWndPlan  ON PAINT DrawRowLines()

return nil

func PreviousYear() /* ********** added by rochinha ********** */
   nYear := nYear - 1
   DrawRowLines()
   oWndPlan:refresh()
   oWndPlan:cTitle := "Kalender [ " + str(nYear,4) + " ]"
   return .t.

func NextYear()     /* ********** added by rochinha ********** */
   nYear := nYear + 1
   DrawRowLines()
   oWndPlan:refresh()
   oWndPlan:cTitle := "Kalender [ " + str(nYear,4) + " ]"
   return .t.

func DrawRowLines ()
//Carles
    local aInfo := oWndPlan:DispBegin() 
//Carles

   LOCAL  I,  nCurrentRows, iZeile
   LOCAL cHeader1     := ""
   LOCAL oSay
   LOCAL hdc
   LOCAL aDays        := {;
      "So","Mo","Di", "Mi", "Do", "Fr", "Sa","So",;
      "Mo","Di", "Mi", "Do", "Fr", "Sa","So",;
      "Mo","Di", "Mi", "Do", "Fr", "Sa","So",;
      "Mo","Di", "Mi", "Do", "Fr", "Sa","So",;
      "Mo","Di", "Mi", "Do", "Fr", "Sa","So","Mo" }

   /* blocked by rochinha
   LOCAL nYear        := YEAR( DATE() ) */
   LOCAL cYear        := STR( nYear, 4 )
   LOCAL dDate, nStart
   LOCAL lSchaltJahr  := ( DAY( CTOD( "29.02." + cYear ) ) <> 0 )
   LOCAL aDaysInMonth := { 31, IIF( lSchaltJahr, 29, 28 ), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
   LOCAL nColOffSet   := 10
   LOCAL aRect1
   LOCAL IMonate      := 0
   LOCAL ITemp        := 0
   local cTest        := ""
   local nEnde

   FOR IMonate := 1 TO 12

      aadd(aPlan,{"","","", "", "", "", "","",;
         "","", "", "", "", "","",;
         "","", "", "", "", "","",;
         "","", "", "", "", "","",;
         "","", "", "", "", "","","",0,0,0 } )

   NEXT

   aRect1 := { 0,0,500,1000}
   FillRect(oWndPlan:hDc,aRect1,oBrush:hBrush)
   iZeile       := 0
   nCurrentRows := 30

   FOR I := 1 TO  13

      SelectObject( oWndPlan:hDc, hPen )
      IF iZeile = 5
         SelectObject( oWndPlan:hDc, hPen1 )
         iZeile := 0
      ENDIF

      //Lines
      oWndPlan:line (nCurrentRows, 1,nCurrentRows, 726 )
      nCurrentRows := nCurrentRows +  18
      iZeile := iZeile + 1

   NEXT

   nCurrentRows:= 50

   FOR I := 1 TO  38

      SelectObject( oWndPlan:hDc, hPen )
      IF iZeile = 5
         SelectObject( oWndPlan:hDc, hPen1 )
         iZeile := 0
      ENDIF

      oWndPlan:line (10,nColOffSet + nCurrentRows,400, nColOffSet + nCurrentRows )
      nCurrentRows := nCurrentRows +  18
      iZeile := iZeile + 1

   NEXT

   nCurrentRows:= 50

   FOR I := 1 TO len(aDays)

      if aDays[I] = "So"

         //Farbhintergrund Sonntag
         SelectObject( oWndPlan:hDc, hPen3 )

         // Sonntag  erste fette Linie
         oWndPlan:line (0,nColOffSet+   10 + nCurrentRows,400, nColOffSet+  10 + nCurrentRows )

         SelectObject( oWndPlan:hDc, hPen )
         oWndPlan:say( 8, nColOffSet+36+I*18,aDays[I],RGB(255,128,0), RGB(125,236,175),planFont,.T.)

      else
         oWndPlan:say( 8, nColOffSet+36+I*18,aDays[I],RGB(255,128,0),16777215,planFont,.T.)

      endif

      nCurrentRows := nCurrentRows +  18

   NEXT

   nCurrentRows := 12

   FOR I := 1 TO  12

      SelectObject( oWndPlan:hDc, hPen )
      IF iZeile = 5
         SelectObject( oWndPlan:hDc, hPen1 )
         iZeile := 0
      ENDIF

      nCurrentRows := nCurrentRows +  18
      dDate := CTOD( "01." + PADL( ALLTRIM(STR( i, 2 )), 2, "0" ) + "." + cYear )
      nStart := DOW( dDate )
      aPlan[I,38] :=  nStart
      aPlan[I,39] :=  30-18+ (18*( aDaysInMonth[i] + nStart - 1 )) //col begin of month
      aPlan[I,40] :=  nStart + aDaysInMonth[i]  //col end of month

      FOR iZeile := nStart TO aDaysInMonth[i] + nStart - 1
         aPlan[I,iZeile] =    ( PADL( ALLTRIM(STR( (iZeile-nStart+1), 2 )), 2, "0" )+ "." + PADL( ALLTRIM(STR( (I), 2 )), 2, "0" ) + "." + cYear )
      NEXT

      cHeader1 :=   OemToAnsi( CMONTH( dDate ) ) //Monate
      oWndPlan:say( nCurrentRows+1, 2, cHeader1,RGB(63,63,63),16777215,planFont,.T.)

   NEXT

   IF (sx > 0 .AND. sx < 13)  .AND.  (sy > 0 .AND. sy < 38)

      IF lMove = .t.
         IZeile := INT((sxTemp-30)/18 ) + 1
         aTemp[IZeile,1]:=10

         FOR ITemp := IZeile+1 TO 12
            aTemp[ITemp,1]:=0
         NEXT

         FOR ITemp := 1 TO 12

            if aTemp[ITemp,1] > 0
               if syTemp > aPlan[ITemp,39] + aPlan[ITemp,38]*18
                  syTemp := aPlan[ITemp,39] + aPlan[ITemp,38]*18
               endif

               IF 30-18+ (18*(ITemp)) >= ClickRow  .AND. ;
                  .NOT.  (30-18+ (18*(ITemp)) = ClickRow  .AND. ;
                  ClickCol > syTemp)

                  FillRect( oWndPlan:hDc, { 30-18+ (18*(ITemp)),ClickCol, 30 +(18*(ITemp)), syTemp}, hBru )

                  IF ITemp > nStartZeile
                     FillRect( oWndPlan:hDc, { 30-18+ (18*(ITemp-1)),ClickCol, 30 +(18*(ITemp-1)), (30 +( 13 + 18*(aPlan[ITemp-1,40])))   }, hBru )
                     FillRect( oWndPlan:hDc, { 30-18+ (18*(ITemp)),  30 + 13 + (18*(aPlan[ITemp,38])), 30 +(18*(ITemp)), syTemp}, hBru )
                  ENDIF

               else
                  FillRect( oWndPlan:hDc, {ClickRow,ClickCol,ClickRow+18,ClickCol+18}, hBru )
               ENDIF
            endif
         NEXT
      ENDIF
   ENDIF

   nCurrentRows := 12

   FOR I := 1 TO  12

      SelectObject( oWndPlan:hDc, hPen )
      IF iZeile = 5
         SelectObject( oWndPlan:hDc, hPen1 )
         iZeile := 0
      ENDIF

      nCurrentRows := nCurrentRows +  18
      dDate := CTOD( "01." + PADL( ALLTRIM(STR( i, 2 )), 2, "0" ) + "." + cYear )
      nStart := DOW( dDate )

      aPlan[I,38] :=  nStart
      aPlan[I,39] :=  30-18+ (18*( aDaysInMonth[i] + nStart - 1 )) //col begin of month
      aPlan[I,40] :=  nStart + aDaysInMonth[i]  //col end of month

      FOR iZeile := nStart TO aDaysInMonth[i] + nStart - 1

         cHeader1 :=    ALLTRIM(str(iZeile-nStart+1)) //Tage
         if aDays[iZeile] = "So"
            oWndPlan:say( nCurrentRows+3,36 + nColOffSet + (iZeile)  *18, ;
               cHeader1, RGB(63,63,63),RGB(125,236,175),planFont,.T.,.T.)
         else
            oWndPlan:say( nCurrentRows+3,36 + nColOffSet + (iZeile)  *18, ;
               cHeader1, RGB(63,63,63),16777215,planFont,.T., .T.)
         ENDIF
      NEXT
   NEXT

   IF (sx > 0 .AND. sx < 13)  .AND.  (sy > 0 .AND. sy < 38)
      oWndPlan:say(sxTemp+20, syTemp-20,  aPlan[sx, sy] + " # "+str(ctod(aPlan[sx, sy])-ctod(startDay)+ 1), RGB(63,63,63), RGB(125,236,175), planFont, .T. )
   endif

oWndPlan:DispEnd( aInfo ) 

return nil

func f_LButtonUp(x,y)

   IF sy > 0   // Quique
      msginfo(startDay + " -- " + aPlan[sx, sy] + "    Tage: " + str( ctod(aPlan[sx, sy])-ctod(startDay)  +1   ))
   ENDIF
   lMove:=.f.

return nil

func  f_MMoved(x,y)
   IF sx <>  (INT((x-30)/18 ) + 1) .OR. sx <> (INT( (y-50-10)/18 ) + 1 )
      sx := INT((x-30)/18 ) + 1
      sy := INT((y-50-10)/18 ) + 1

      IF x < 30
         sx := 0
         x  := 0
      ENDIF

      sxTemp := x
      syTemp :=   59 +      sy * 18

      oWndPlan:refresh()

   ENDIF

return nil

func f_bLClicked(x,y)
   local ITemp:=0

   sx := INT((x-30)/18 ) + 1
   sy := INT((y-50-10)/18 ) + 1

   IF sy > 0   // Quique
      startDay := aPlan[sx, sy]
      nStartZeile := sx
      ClickCol := INT((y - 30)/18)*18  + 18 + 7
      ClickRow := (INT((x-30)/18 ))*18 + 30

      FOR ITemp := 1 TO 12
         aTemp[ITemp,1]:=0
      NEXT

      FillRect( oWndPlan:hDc, {ClickRow,ClickCol,ClickRow+18,ClickCol+18}, hBru )
      oWndPlan:refresh()

      lMove:=.t.
   ENDIF

return nil

Posted: Fri Jul 25, 2008 11:32 am
by Kleyber
Otto and all,

Thanks for sharing this code. It`s very very good!! I would like to know if it`s possible do increase the week`s letters to 3 instead of 2? I mean, instead of

LOCAL aDays := {;
"So","Mo" ...

it could be:

LOCAL aDays := {;
"Son","Mon" ...

Best Regards,

Posted: Fri Jul 25, 2008 6:43 pm
by Rochinha
Otto,

The Vertical Scolling is better.

Your Pick Date Code is a Best Code Of Year!

Thanks at lot.