HELP TO COMPLETE A NEW CLASS : FWCALENDAROFFICE

HELP TO COMPLETE A NEW CLASS : FWCALENDAROFFICE

Postby MdaSolution » Fri Jan 21, 2011 11:24 pm

I wish create this class : TcalendarOffice

COULD U HELP ME PLEASE ?

I explain you how I thinked it

I thinked to divide all into 4 areas : top_left, Left, center_right_top, center.

on top_left we insert a title
on Left we insert the list of Hours ( from 00:00 to 24:00)
center_right_top we insert the calendar ( a week,or a mounth, or 3days)
center we insert the graphics

all parts are as a panel control but only on the area center i can move and click the mouse and draw the graphics


we called them : oTitle,oDays,oHours,oGraph

the oHours can be ltime1, ltime15, ltime30, ltime45 - sample 00:00 , 00:15, 00:30, 00:45 -
the oHours is static ( I used an arra to create it) but we can use easy a xbrowse to show it

the test

Code: Select all  Expand view
#include "FiveWin.ch"
#include "Constant.ch"
#include 'xbrowse.ch'
#include "Splitter.ch"

#DEFINE TRUE     .T.
#DEFINE FALSE    .F.

#define HSTEP  20
#define VSTEP  25

#define GRIDROW 50
#define GRIDCOL 50

 #define TA_LEFT                      0
#define TA_RIGHT                     2
#define TA_CENTER                    6

REQUEST DBFCDX, DBFFPT
external ordkeyno, ordkeycount,ordcreate


STATIC oWnd,oTitle,oDays,oHours,oGraph
STATIC oFont
STATIC oSplit1,oSplit2
STATIC nHoriz1, nHoriz2
STATIC ltime1, ltime15, ltime30, ltime45



STATIC oPenL,oPenR
STATIC oPen1,oPen2,oPen3,oPen4

STATIC nGridCol   := GRIDCOL
STATIC nGridRow   := GRIDROW







Function test()

nVertic := 0
nHoriz1 := 0
nHoriz2 := 0

  RddSetDefault( "DBFCDX" )
  SetHandleCount( 128 )


DEFINE FONT oFont NAME "MS Sans Serif" SIZE 0,-8 BOLD

DEFINE WINDOW oWnd TITLE "NEW FW CALENDAR"

DEFINE BUTTONBAR obar 3D OF oWnd SIZE 42,42   2007


 SET MESSAGE OF oWnd TO "New FW Calendar  " KEYBOARD CLOCK DATE NOINSET   2007



// type of timeline
ltime15:=.f.
ltime30:=.f.
ltime45:=.f.




    //TITLE
    oTitle:=TCalendarOffice():New(40,0,200,28,oWnd,FALSE)
    oTitle:bPainted    := {|| Title() }



    //Days
    oDays:=TCalendarOffice():New(40,100,400,40,oWnd,FALSE)
    oDays:bPainted    := {|| Week() }

    //TIME
    oHours:=TCalendarOffice():New(65,0,100,300,oWnd,FALSE)
    oHours:bPainted    := {|| Hours() }


    // GRAPHICS    // ONLY FOR THIS i USE THE MOUSE DRAW
    oGraph:=TCalendarOffice():New(65,100,400,300,oWnd,TRUE)
    oGraph:bPainted := {|| Graphics() }


     oGraph:nGridCol  :=  GRIDCOL
     oGraph:nGridRow  :=  GRIDROW





@ 65,0   SPLITTER oSplit1 WINDOW  oWnd ;
         HORIZONTAL ;
         PREVIOUS CONTROLS oTitle ;
         HINDS CONTROLS oHours ;
         SIZE 200,0 PIXEL

@ 65,205 SPLITTER oSplit2 WINDOW  oWnd ;
         HORIZONTAL ;
         PREVIOUS CONTROLS oDays ;
         HINDS CONTROLS oGraph ;
         SIZE 400,0 PIXEL

oSplit1:lStatic := .t. ; oSplit1:Hide()
oSplit2:lStatic := .t. ; oSplit2:Hide()

@ 0, 100  SPLITTER oSplit WINDOW  oWnd ;
        VERTICAL ;
        PREVIOUS CONTROLS oTitle, oSplit1, oHours ;
        HINDS CONTROLS oDays, oSplit2, oGraph ;
        LEFT MARGIN 50 ;
        RIGHT MARGIN 70 ;
        SIZE 1, 336 PIXEL ;
        3DLOOK





nVertic := 0
nHoriz1 := 0
nHoriz2 := 0



DEFINE SCROLLBAR oHours:oHScroll OF oHours ;
       HORIZONTAL ;
       RANGE 0, 200/HSTEP ;
       PAGESTEP 5;
       ON UP ( nHoriz1 += HSTEP, HScroll1() ) ;
       ON DOWN ( nHoriz1 -= HSTEP, HScroll1() ) ;
       ON PAGEUP ( nHoriz1 += 5*HSTEP, HScroll1() ) ;
       ON PAGEDOWN ( nHoriz1 -= 5*HSTEP, HScroll1() ) ;
       ON THUMBPOS ( nHoriz1 -= ( nPos-oHours:oHScroll:GetPos() )*HSTEP, ;
                     oHours:oHScroll:SetPos(nPos), ;
                     HScroll1() )





    DEFINE SCROLLBAR oGraph:oHScroll OF oGraph ;
          HORIZONTAL ;
          RANGE 0, 3600/HSTEP ;
          PAGESTEP 5;
          ON UP ( nHoriz2 += HSTEP, HScroll2() ) ;
          ON DOWN ( nHoriz2 -= HSTEP, HScroll2() ) ;
          ON PAGEUP ( nHoriz2 += 5*HSTEP, HScroll2() ) ;
          ON PAGEDOWN ( nHoriz2 -= 5*HSTEP, HScroll2() ) ;
          ON THUMBPOS ( nHoriz2 -= ( nPos-oGraph:oHScroll:GetPos() )*HSTEP, ;
                        oGraph:oHScroll:SetPos(nPos), ;
                        HScroll2() )

   DEFINE SCROLLBAR oGraph:oVScroll OF oGraph ;
          VERTICAL ;
          RANGE 0, 400/VSTEP ;
          PAGESTEP 5;
          ON UP ( nVertic += VSTEP, VScroll() ) ;
          ON DOWN ( nVertic -= VSTEP, VScroll() ) ;
          ON PAGEUP ( nVertic += 5*VSTEP, VScroll() ) ;
          ON PAGEDOWN ( nVertic -= 5*VSTEP, VScroll() ) ;
          ON THUMBPOS ( nVertic -= ( nPos-oGraph:oVScroll:GetPos() )*VSTEP, ;
                        oGraph:oVScroll:SetPos(nPos), ;
                        VScroll() )




    ACTIVATE WINDOW oWnd MAXIMIZED;
    ON PAINT (oSplit:AdjClient(), oSplit1:AdjLeft(), oSplit2:AdjRight())

  SET RESOURCES TO
  SET LOOK3D OFF
  RELEASE FONT oFont


  RETURN nil


//----------------------------------------------------------------------------//
  Function  Title()
  oTitle:Say( 10, 2+nHoriz1, "Times", , , oFont, .T., .T. )
  oTitle:Line( 0, 35+nHoriz1, 36, 35+nHoriz1 )
  RETURN NIL


//----------------------------------------------------------------------------//

 FUNCTION Week()
   local n, m
   local nHeight := (oWnd:nHeight - 20 ) / 7
   local nWidth := oSplit2:nLong / 6
   local cDay
   LOCAL nColonna :=GRIDCOL
   LOCAL dData, cCol

   dData:=(date())+1
   nGridCol := oSplit2:nLong / 6

  nColonna := nGridCol
  for n = 0 to 6
      cDay :=  oemtoansi(CDoW( dData + ( n - 1 ) )  + " " +;
             PADL( DAY( dData + ( n - 1 ) ), 2, "0" ) + " " +  cmonth( dData + ( n - 1 )) + " " )
     cCol:= ( n * nWidth ) + ( nWidth / 2 )
    oDays:Say ( 1, cCol,  cDay, , , , .T., .T., TA_CENTER   )
    oDays:Line( 0, nColonna, 120, nColonna, oPen2 )
    nColonna += nGridCol
 next

  RETURN nil





//----------------------------------------------------------------------------//

 FUNCTION Hours()
  LOCAL nLinea := 0
  Local  aOre := {}

  FOR nOre = 0 TO 23

   AADD( aOre, STRZERO( nOre, 2 ) + ".00" )     //time 1 Hour

    IF ltime15
       AADD( aOre, STRZERO( nOre, 2 ) + ".15" )
    endif

    IF ltime30
       AADD( aOre, STRZERO( nOre, 2 ) + ".30" )
    endif

  IF ltime45
    AADD( aOre, STRZERO( nOre, 2 ) + ".45" )
 endif

NEXT

       // write the HOURS
       For n= 1 to Len(aOre)
                  oHours:Say( nLinea+nVertic+15, 18+nHoriz1+15, aOre[n], , , oFont, .T., .T., TA_CENTER )
                  nLinea += GRIDROW
                  oHours:Line( nLinea+nVertic, 0+nHoriz1, nLinea+nVertic, 361+nHoriz1 )
        next

RETURN nil






//----------------------------------------------------------------------------//

 FUNCTION Graphics()

  LOCAL nStartGraph, nEndGraph

  LOCAL nReg := RECNO()
  Local dDate := Date() - Day( Date() ) + 1
  Local nRow  := 0               // Gridrow
  LOCAL nColumn := nGridCol //GRIDCOL
  LOCAL nLinea := 0
  LOCAL nColumnaInicio, nColumnaFinal
  LOCal nRowInit
  Local nRowEnd
  LOCAL nGraphRow := 0

// HORIZZONTAL LINES
   DO WHILE nRow < oSplit:nLong
     oGraph:Line( nRow ,0, nRow, oWnd:nWidth,  oPen3 )
     nRow += GRIDROW
   ENDDO

// VERTICAL LINES
   DO WHILE nColumn <= oSplit2:nLong
     oGraph:Line( 0, nColumn, oWnd:nHeight, nColumn, oPen2 )
     nColumn += nGridCol //GRIDCOL
  ENDDO


 /*  GO TOP

   DO WHILE .NOT.EOF()

     nColonnaInit := ( Calendar->day - dDate ) * 16
     nColonnaEnd := ( Calendar->day - dDate + 1 ) * 16

    IF calendar->Type=1
              oGraph:RecordBox( nrow, nColonnaInit, nRow+14, nColonnaEnd, oPenR ,nReg)
    ELSEIF calendar->Type=2
              oGraph:RecordBox( nrow, nColonnaInit, nRow+14, nColonnaEnd, oPenL ,nReg)
    ENDIF
     SKIP 1
     nrow += 22

  ENDDO

  GOTO nReg
   */


   RETURN nil


//----------------------------------------------------------------------------//

FUNCTION HScroll1()

  LOCAL hWnd
  LOCAL aRect

  STATIC nH1 := 0

  IF nHoriz1<-200 .OR. nHoriz1>0
     nHoriz1 := nH1
     RETURN nil
  ENDIF

  hWnd := oTitle:hWnd
  aRect := GetClientRect( hWnd )
  ScrollWindow( hWnd, nHoriz1-nH1, 0, aRect, aRect )

  hWnd := oHours:hWnd
  aRect := GetClientRect( hWnd )
  ScrollWindow( hWnd, nHoriz1-nH1, 0, aRect, aRect )
  oTitle:REFRESH()
  oHours:REFRESH()
  nH1 := nHoriz1

RETURN nil



  FUNCTION HScroll2()

  LOCAL hWnd
  LOCAL aRect

  STATIC nH2 := 0

  IF nHoriz2<-3600 .OR. nHoriz2>0
     nHoriz2 := nH2
     RETURN nil
  ENDIF

  hWnd := oDays:hWnd
  aRect := GetClientRect( hWnd )
  ScrollWindow( hWnd, nHoriz2-nH2, 0, aRect, aRect )

  hWnd :=  oGraph:hWnd
  aRect := GetClientRect( hWnd )
  ScrollWindow( hWnd, nHoriz2-nH2, 0, aRect, aRect )

            oDays:REFRESH()
            oGraph:REFRESH()

  nH2 := nHoriz2

RETURN nil

* --------------------------------

FUNCTION VScroll()

  LOCAL hWnd
  LOCAL aRect

  STATIC nV := 0

  IF nVertic<-400 .OR. nVertic>0
     nVertic := nV
     RETURN nil
  ENDIF

  hWnd := oHours:hWnd
  aRect := GetClientRect( hWnd )
  ScrollWindow( hWnd, 0, nVertic-nV, aRect, aRect )

  hWnd :=  oGraph:hWnd
  aRect := GetClientRect( hWnd )
  ScrollWindow( hWnd, 0, nVertic-nV, aRect, aRect )

  nV := nVertic

RETURN nil



//----------------------------------------------------------------------------//

FUNCTION create_dbf()

      local astruc := { { "day", "d", 8, 0 },;
                        { "starttime"   , "C", 5, 0 },;
                        { "endtime"     , "C", 5, 0 },;
                        { "subject"     , "C", 50, 0 },;
                        { "type"        , "N", 1, 0 },;
                        { "body"            , "M", 10, 0 } }

    cAlias := "Calendar"

    if !file( "calendar.dbf")

        dbcreate( cAlias, aStruc, "DBFCDX", .t., cAlias )

        (cAlias)->( OrdCreate( cAlias, "day", "day" ) )
        (cAlias)->( OrdCreate( cAlias, "starttime", "starttime" ) )
    else

       dbuseArea( .t., "DBFCDX", cAlias, cAlias, .t. )
       (cAlias)->( OrdCreate( cAlias, "day", "day" ) )
        (cAlias)->( OrdCreate( cAlias, "starttime", "starttime" ) )


    endif

    (cAlias)->( OrdListAdd( cAlias ) )

Return Nil
//----------------------------------------------------------------------------//
 
FWH .. BC582.. xharbour
User avatar
MdaSolution
 
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

Re: HELP TO COMPLETE A NEW CLASS : FWCALENDAROFFICE

Postby MdaSolution » Fri Jan 21, 2011 11:30 pm

the TcalendarOffice class Alpha

Code: Select all  Expand view
// CLASS TO CREATE CALENDAR LIKE OFFICE 2007

CLASS TCalendarOffice FROM TCONTROL

   CLASSDATA lRegistered AS LOGICAL

 DATA aItems
 DATA nBoxTop, nBoxLeft, nBoxBottom, nBoxRight AS NUMERIC INIT 0
 DATA nMove,nGRIDCOL,nGRIDROW   AS NUMERIC INIT 0
 DATA nItem,lBoxDraw
 DATA lVScroll, lHScroll

   DATA bPresed ,uGrid



   CLASSDATA nPoint


  METHOD New( nTop, nLeft, nWidth, nHeight, oWnd,lBoxDraw,bChange, bLDblClicked, bPresed,uGrid )  CONSTRUCTOR
  METHOD Display() INLINE ::BeginPaint(), ::Paint(), ::EndPaint(), 0
  METHOD Paint()
  METHOD DrawBox() INLINE RectDotted( ::hWnd, ::nBoxTop, ::nBoxLeft, ::nBoxBottom, ::nBoxRight )
  METHOD LButtonUp( nRow, nCol, nFlags )
  METHOD MouseMove( nRow, nCol, nFlags )
  METHOD LButtonDown( nRow, nCol, nFlags )
  METHOD Line( nTop, nLeft, nBottom, nRight, oPen )
  METHOD Rectang( nTop, nLeft, nBottom, nRight, oPen )
  METHOD Say( nRow, nCol, cText, nClrFore, nClrBack, oFont, lPixel,lTransparent, nAlign )
  METHOD RecordBox( nTop, nLeft, nBottom, nRight, oPen ,nrecord)
  METHOD Ldblclick( nRow, nCol, nKeyFlags )
  METHOD MouseDown( nRow, nCol, nKeyFlags )

 ENDCLASS


METHOD New( nTop, nLeft, nWidth, nHeight, oWnd,lBoxDraw,lVScroll, lHScroll,bChange, bLDblClicked, bPresed,uGrid ) CLASS TCalendarOffice

DEFAULT oWnd := GetWndDefault()  ,;
        lBoxDraw := FALSE  ,;
         lVScroll := .f., lHScroll := .f.

   ::aItems   := {}
   ::nTop     = nTop
   ::nLeft    = nLeft
   ::nBottom  = nTop + nHeight - 1
   ::nRight   = nLeft + nWidth - 1
   ::oWnd     = oWnd


   ::bChange  := bChange
   ::bLDblClick := bLDblClicked
   ::bPresed  := bPresed

   ::uGrid    := uGrid      // for a grid

   ::nStyle   := nOr( WS_CHILD,;
                      If( lVScroll, WS_VSCROLL, 0 ),;
                      If( lHScroll, WS_HSCROLL, 0 ),;
                          WS_VISIBLE, WS_TABSTOP)
   ::nClrPane          = CLR_WHITE

   ::lBoxDraw   = lBoxDraw

   ::Register()




  if oWnd:lVisible
      ::Create()
      ::Default()
      ::lVisible = .t.
      oWnd:AddControl( Self )
       if ::oWnd:oBrush != nil
         ::SetBrush( ::oWnd:oBrush )
      endif
   else
      oWnd:DefControl( Self )
      ::lVisible  = .f.
   endif

  if lVScroll
      DEFINE SCROLLBAR ::oVScroll VERTICAL OF Self
   endif
   if lHScroll
      DEFINE SCROLLBAR ::oHScroll HORIZONTAL OF Self
   endif


RETURN SELF
//----------------------------------------------------------------------------//

METHOD Paint() CLASS TCalendarOffice
   local nTop, nLeft, nHeight, nWidth, nBevel
   local aInfo := ::DispBegin()
   FillRect( ::hDC, GetClientRect( ::hWnd ), ::oBrush:hBrush )
   if ::oClient != nil .and. ( nBevel := ::oClient:nClientBevel ) > 0
      nBevel  -= 1
      nTop    := nBevel
      nLeft   := nBevel
      nHeight := ::nHeight - nBevel - 1
      nWidth  := ::nWidth - nBevel - 1
      if ::oTop != nil
         nTop += ::oTop:nHeight
      endif
      if ::oBottom != nil
         nHeight -= ::oBottom:nHeight
      endif
      if ::oLeft != nil
         nLeft += ::oLeft:nWidth
      endif
      if ::oRight != nil
         nWidth -= ::oRight:nWidth
      endif
      WndBoxIn( ::hDC, nTop, nLeft, nHeight, nWidth )
   endif

   if ValType( ::bPainted ) == "B"
      Eval( ::bPainted, ::hDC, ::cPS, Self )
   endif

   ::DispEnd( aInfo )
RETURN NIL

//----------------------------------------------------------------------------//


//----------------------------------------------------------------------------//

METHOD LButtonDown( nRow, nCol, nFlags ) CLASS TCalendarOffice

   if ::bLClicked != nil
      Eval( ::bLClicked, nRow, nCol, nFlags )
   else
      ::lBoxDraw   = .t.
      ::nBoxTop    = nRow
      ::nBoxLeft   = nCol
      ::nBoxBottom = nRow
      ::nBoxRight  = nCol
      ::Capture()
      ::DrawBox()
   endif


return nil


//----------------------------------------------------------------------------//

METHOD MouseMove( nRow, nCol, nFlags ) CLASS TCalendarOffice

   if ::lBoxDraw
      ::DrawBox()
      ::nBoxBottom = nRow
      ::nBoxRight  = nCol



      ::DrawBox()


   endif

return Super:MouseMove( nRow, nCol, nFlags )

//----------------------------------------------------------------------------//

METHOD LButtonUp( nRow, nCol, nFlags ) CLASS TCalendarOffice

   if ::lBoxDraw
      ::DrawBox()
      ::lBoxDraw = .f.
      ReleaseCapture()

 // ::nWidth := ::nBoxRight - ::nBoxLeft
 //  ::nHeight := ::nBoxBottom - ::nBoxTop

  // Super:ScrollAdjust()
  // Super:refresh( .t. )


endif


//----------------------------------------------------------------------------//

 METHOD Ldblclick( nRow, nCol, nKeyFlags )  CLASS TCalendarOffice

    ::lCaptured := FALSE

      if ::uGrid  != Nil
          ::uGrid:ldblclick( nRow, nCol, nKeyFlags )
      ENDIF

        Super:LDblClick( nRow, nCol, nKeyFlags )

 return Nil








  METHOD MouseDown( nRow, nCol, nKeyFlags )    CLASS TCalendarOffice

     IF ::lBoxdraw
        ::DrawBox()
   ::nBoxTop    = nRow
   ::nBoxLeft   = nCol
   ::nBoxBottom = nRow
   ::nBoxRight  = nCol
     SetCapture( ::oWnd:hWnd )
   ::DrawBox()

 ENDIF
    return Nil

//----------------------------------------------------------------------------//




//----------------------------------------------------------------------------//

 METHOD Line( nTop, nLeft, nBottom, nRight, oPen ) CLASS TCalendarOffice

   local hPen := if( oPen = nil, 0, oPen:hPen )

   ::GetDC()
   MoveTo( ::hDC, nLeft, nTop )
   LineTo( ::hDC, nRight, nBottom, hPen )
   ::ReleaseDC()

return nil

//----------------------------------------------------------------------------//

METHOD Rectang( nTop, nLeft, nBottom, nRight, oPen ) CLASS TCalendarOffice
   local hPen := if( oPen = nil, 0, oPen:hPen )
   IIF( nrecord == nil , nrecord := 0  , )
   ::GetDC()
   Rectangle( ::hDC, nTop, nLeft, nBottom, nRight, hPen )
   ::ReleaseDC()
   return nil

//----------------------------------------------------------------------------//
METHOD Say( nRow, nCol, cText, nClrFore, nClrBack, oFont, lPixel,;
      lTransparent, nAlign ) CLASS TCalendarOffice

   DEFAULT nClrFore := ::nClrText,;
      nClrBack := ::nClrPane,;
      oFont    := ::oFont,;
      lPixel   := .f.,;
      lTransparent := .f.

   if ValType( nClrFore ) == "C"
      nClrBack = nClrFore
      nClrFore = nGetForeRGB( nClrFore )
      nClrBack = nGetBackRGB( nClrBack )
   endif

   ::GetDC()
DEFAULT nAlign := GetTextAlign( ::hDC )

   WSay( ::hWnd, ::hDC, nRow, nCol , cValToChar( cText ), nClrFore, nClrBack,;
      If( oFont != nil, oFont:hFont, 0 ), lPixel, lTransparent, nAlign )
     ::ReleaseDC()

return nil

//----------------------------------------------------------------------------//

 METHOD RecordBox( nTop, nLeft, nBottom, nRight, oPen ,nrecord) CLASS TCalendarOffice
   local hPen := if( oPen = nil, 0, oPen:hPen )
   Local nX := oPen:nWidth/2
   IIF( nrecord == nil , nrecord := 0  , )
   ::GetDC()
   Rectangle( ::hDC, nTop, nLeft, nBottom, nRight, hPen )
   ::ReleaseDC()
   if nrecord > 0
      aadd(::aItems,{nTop-nX,nLeft-nX,nBottom+nX,nRight+nX,nrecord})
   endif
return nil

//----------------------------------------------------------------------------//


 
FWH .. BC582.. xharbour
User avatar
MdaSolution
 
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 24 guests