/*
* Proyecto: modelos
* Fichero: NGIF.prg
* Descripción:
* Autor:
* Fecha: 20/04/2021
*/
#include "fivewin.ch"
#include "gif.ch"
CLASS TGif FROM TControl
DATA hGif
DATA cFilename
DATA lAdjust
DATA nSizingType
CLASSDATA lRegistered
METHOD New( oWnd, cGifFile, nRow, nCol,;
nHeight, nWidth, oCursor, lAdjust, bAction )
METHOD Redefine( nId, oWnd, cGifFile, lAdjust,bAction )
METHOD GetData() INLINE If( ! Empty( ::hGif ), GetGifInfo( ::hGif ),)
METHOD Play() INLINE FWGifPlay( ::hGif )
METHOD Stop() INLINE FWGifStop( ::hGif )
METHOD Restart() INLINE FWGifRestart( ::hGif )
METHOD IsRunning() INLINE FWGifIsRunning( ::hGif )
METHOD Destroy() INLINE FWGifEnd()
METHOD SetFile( cFile ) INLINE ::cFileName := cFile, SetWindowText( ::hGif, cFile )
METHOD SetSizing( nType ) INLINE FWSetGIFSizing( ::hGif, nType )
METHOD Refresh()
METHOD ReSize( nSizeType, nWidth, nHeight ) INLINE ::SetSize( nWidth, nHeight, .T. ),;
WndSetSize( ::hGif, nWidth, nHeight, .T. )
METHOD Initiate( hDlg ) INLINE ::Super:Initiate( hDlg ), ::Default()
METHOD Default()
ENDCLASS
//----------------------------------------------------------------//
METHOD New( oWnd, cGifFile, nRow, nCol,;
nHeight, nWidth, oCursor, lAdjust, bAction ) CLASS TGif
local aData, nNewWidth, nNewHeight, nSizingType
local hRes
local cDir, cTempfile
DEFAULT oWnd := GetWndDefault(),;
nRow := 0,;
nCol := 0,;
lAdjust := .F.
::nTop = nRow
::nLeft = nCol
::nStyle = nOR( WS_CHILD, WS_VISIBLE, WS_CLIPCHILDREN )
::bLClicked = bAction
::nSizingType = FWGIF_SIZING_FILE
if nHeight == nil .or. nWidth == nil
::nBottom = 100
::nRight = 100
else
::nBottom = nHeight + nRow
::nRight = nWidth + nCol
::nSizingType = FWGIF_SIZING_CLIP
endif
::oWnd = oWnd
::oCursor = oCursor
::cFileName = cGifFile
::oBrush = oWnd:oBrush
::lAdjust = lAdjust
::Register( )
if ! Empty( oWnd:hWnd )
::Create()
::lVisible = .t.
oWnd:AddControl( Self )
else
oWnd:DefControl( Self )
::lVisible = .f.
endif
::Default()
return self
//----------------------------------------------------------//
METHOD Redefine( nId, oWnd, cGifFile, lAdjust,bAction )
DEFAULT lAdjust := .T.
::nId = nId
::cFileName = cGifFile
::lAdjust = lAdjust
::bLClicked = bAction
::Register( nOR( CS_VREDRAW, CS_HREDRAW ) )
if oWnd != nil
::oWnd = oWnd
oWnd:DefControl( Self )
endif
return Self
//----------------------------------------------------------//
METHOD Default() CLASS TGif
local hRes, cDir, cTempFile
local cGifFile := ::cFileName
local aData, nNewWidth := 100, nNewHeight := 100, nSizingType
if ! Empty( cGifFile ) .and. ! File( cGifFile )
hRes = FindResource( GetResources(), cGifFile, 10 )
If Empty( hres )
return nil
else
cDir = GetEnv( "TEMP" )
if Empty( cDir )
cDir = GetEnv( "TMP" )
endif
cTempfile = cDir + cTempFile( "\", "gif" )
RCDataToFile( 0, cGifFile, cTempfile )
endif
endif
If ! Empty( cTempfile )
::hGif = FWGifWindow( cTempFile, 0, 0, ::nWidth, ::nHeight, ::hWnd )
else
::hGif = FWGifWindow( cGifFile, 0, 0, ::nWidth, ::nHeight, ::hWnd )
endif
aData = ::GetData()
if ! ::lAdjust
if ! Empty( aData )
nNewWidth = aData[ FWGIF_WIDTH ]
nNewHeight = aData[ FWGIF_HEIGHT ]
endif
else
nNewWidth = ::nWidth
nNewHeight = ::nHeight
endif
::ReSize( , nNewWidth, nNewHeight )
if ::lAdjust
::nSizingType = FWGIF_SIZING_STRETCH
endif
::SetSizing( ::nSizingType )
If ! Empty( cTempfile )
FErase( cTempfile )
endif
return nil
//----------------------------------------------------------//
METHOD Refresh() CLASS TGif
local nSizingType := ::nSizingType
local aData := ::GetData()
local nNewWidth, nNewHeight
if ! Empty( aData )
nNewWidth = aData[ FWGIF_WIDTH ]
nNewHeight = aData[ FWGIF_HEIGHT ]
endif
if ::lAdjust
if nSizingType != FWGIF_SIZING_STRETCH
nSizingType = FWGIF_SIZING_STRETCH
endif
else
if nSizingType = FWGIF_SIZING_CLIP
nNewWidth = ::nWidth
nNewHeight = ::nHeight
else
nSizingType = FWGIF_SIZING_FILE
if ! Empty( aData )
nNewWidth = aData[ FWGIF_WIDTH ]
nNewHeight = aData[ FWGIF_HEIGHT ]
endif
endif
endif
::SetSizing( nSizingType )
::ReSize( , nNewWidth, nNewHeight )
::nSizingType = nSizingType
return ::Super:Refresh()