/*
 * Xailer source code:
 *
 * Pager.prg
 * Clase TPager()
 *
 * Copyright 2003, 2007 Jose Lalin
 * Copyright 2003, 2007 Jose F. Gimenez
 * Copyright 2003, 2007 Xailer.com
 * All rights reserved
 *
 */

#include "Xailer.ch"
#include "CommCtrl.api"


//--------------------------------------------------------------------------

CLASS XPager FROM TWinControl

PUBLISHED:
   PROPERTY nWidth            INIT 120
   PROPERTY nHeight           INIT 30
   PROPERTY nPosition         INIT 0   READ GetPos WRITE SetPos
   PROPERTY nScrollIncrement  INIT 8
   PROPERTY nOrientation      INIT orHORIZONTAL VALUES orHORIZONTAL, orVERTICAL
   PROPERTY lAutoScroll       INIT .F. WRITE METHOD SetAutoScroll
   PROPERTY lTransparent      INIT .F.

PROTECTED:
   DATA cWinClassName   INIT WC_PAGESCROLLER
   DATA oChild

PUBLIC:
   CONSTRUCTOR Create( oParent )

RESERVED:
   METHOD SetAutoScroll( lAutoScroll )
   METHOD Notify()
   METHOD AlignControls()        INLINE ::SendMsg( PGM_RECALCSIZE, 0, 0 )
   METHOD SetChild( hChild )     INLINE ::SendMsg( PGM_SETCHILD, 0, hChild )
   METHOD InsertControl( oCtrl ) INLINE ::Super:InsertControl( oCtrl ), ;
                                        ::oChild := oCtrl, ;
                                        ::SetChild( oCtrl:Handle )
   METHOD RemoveControl( oCtrl ) INLINE ::Super:RemoveControl( oCtrl ), ;
                                        ::oChild := Nil, ;
                                        ::SetChild( 0 )

   METHOD ForwardMouse( lForward )  INLINE ::SendMsg( PGM_FORWARDMOUSE, lForward, 0 )

   METHOD GetBkColor()           INLINE ::SendMsg( PGM_GETBKCOLOR, 0, 0 )
   METHOD SetBkColor( nColor )   INLINE ::SendMsg( PGM_SETBKCOLOR, 0, nColor )

   METHOD GetBorder()            INLINE ::SendMsg( PGM_GETBORDER, 0, 0 )
   METHOD SetBorder( nSize )     INLINE ::SendMsg( PGM_GETBORDER, 0, nSize )

   METHOD GetPos()               INLINE ::SendMsg( PGM_GETPOS, 0, 0 )
   METHOD SetPos( nPos )         INLINE ::SendMsg( PGM_SETPOS, 0, nPos )

   METHOD GetButtonSize()        INLINE ::SendMsg( PGM_GETBUTTONSIZE, 0, 0 )
   METHOD SetButtonSize( nSize ) INLINE ::SendMsg( PGM_SETBUTTONSIZE, 0, nSize )

   METHOD GetButtonState( nButtonID ) INLINE ::SendMsg( PGM_GETBUTTONSTATE, 0, nButtonID )

RESERVED:
   METHOD WMNCHitTest()    VIRTUAL
   METHOD WMPrintClient()  VIRTUAL

ENDCLASS

//--------------------------------------------------------------------------

METHOD Create( oParent ) CLASS XPager

   InitCommonControls( ICC_PAGESCROLLER_CLASS )

   ::nCtlStyle := nExclude( ::nCtlStyle, PGS_VERT, PGS_HORZ )

   IF ::nOrientation == orVERTICAL
      ::nCtlStyle := nOr( ::nCtlStyle, PGS_VERT )
   ELSE
      ::nCtlStyle := nOr( ::nCtlStyle, PGS_HORZ )
   ENDIF

   ::Super:Create( oParent )

   ::SetAutoScroll()

RETURN Self

//--------------------------------------------------------------------------

METHOD SetAutoScroll( lAutoScroll ) CLASS XPager

   DEFAULT lAutoScroll TO ::FlAutoScroll

   ::FlAutoScroll := lAutoScroll
   ::ChangeCtlStyle( PGS_AUTOSCROLL, lAutoScroll )

RETURN ::FlAutoScroll

//--------------------------------------------------------------------------

#pragma BEGINDUMP

#define _WIN32_IE 0x0400

#include <windows.h>
#include <commctrl.h>
#include <xailer.h>

//--------------------------------------------------------------------------

HB_FUNC_STATIC( XPAGER_NOTIFY )
{
   LPNMHDR nmhdr = (LPNMHDR) hb_parnl( 2 );

   switch( nmhdr->code )
   {
      case PGN_CALCSIZE:
      {
         PHB_ITEM Self = hb_stackSelfItem();
         PHB_ITEM oChild = XA_ObjGetItemCopy( Self, "oChild" );
         LPNMPGCALCSIZE pgcs = (LPVOID) nmhdr;

         if( HB_IS_OBJECT( oChild ) )
            {
            pgcs->iWidth = XA_ObjGetNL( oChild, "nWidth" );
            pgcs->iHeight = XA_ObjGetNL( oChild, "nHeight" );
            }
         hb_itemRelease( oChild );
         break;
      }
      case PGN_SCROLL:
      {
         PHB_ITEM Self = hb_stackSelfItem();
         // NOTA: Hay un bug en la estructura NMPGSCROLL de MinGW, y por eso
         // se utiliza un offset directo al valor que hay que cambiar - [JFG]
         //LPNMPGSCROLL pgs = (LPVOID) nmhdr;
         WORD *iScroll = (LPWORD) nmhdr + 21;

         //pgs->iScroll = XA_ObjGetNL( Self, "nScrollIncrement" );
         *iScroll = XA_ObjGetNL( Self, "nScrollIncrement" );
         break;
      }
   }

   hb_retnl( 0 );
}

#pragma ENDDUMP

//--------------------------------------------------------------------------
