// FWExplorer
// Cnl - 10/06/2016
#include "fivewin.ch"
#include "RichEdi5.ch"
//----------------------------------------------------------------------------//
REQUEST HB_CODEPAGE_ESWIN
Static oRTF
Static cRTF
Static nFilter
Static cDirName
Static aFilesTxt
Static aFilesImg
Static aFilesObj
Static aFilesAll
//----------------------------------------------------------------------------//
function Main()
local aImages
local oWnd
local oFont
local oBrush
local oBrw
local nWBrw := 300
aFilesTxt := { "RTF", "TXT", "PRG", "C", "CPP", "H", "CH", "RC", "INI", "BAT", "MAK", "XML", "LOG" }
aFilesImg := { "BMP", "PNG", "JPG", "ICO", "DIB", "PCX", "GIF", "WMF" }
aFilesObj := { "DOC", "XLS", "PPT", "PDF", "DOCX", "XLSX" }
aFilesAll := { "DBF" }
FW_SetUnicode( .t. )
HB_CDPSELECT( "ESWIN" )
HB_SETCODEPAGE( "UTF8" ) // Harbour (not xHarbour) to display unicode filenames
nFilter := 0
cDirName := hb_CurDrive() + ":\" + CurDir()
aImages := ReadFolder()
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
//DEFINE BRUSH oBrush FILE "..\bitmaps\backgrnd\stone.bmp"
DEFINE WINDOW oWnd TITLE " FWExplorer: Visor de Documentos - [ TRichEdit Control ]"
oWnd:SetFont( oFont )
SET MESSAGE OF oWnd TO "" 2015
DEFINE BUTTONBAR oWnd:oBar SIZE 70, 32 2015
DEFINE BUTTON OF oWnd:oBar PROMPT "Exit" CENTER ACTION ( oWnd:End() )
DEFINE BUTTON OF oWnd:oBar PROMPT "Rtf" CENTER ACTION ( nFilter := 1, ;
oBrw:aArrayData := ReadFolder(), oBrw:Refresh( .t. ), VerDoc( oBrw ) )
DEFINE BUTTON OF oWnd:oBar PROMPT "Text" CENTER ACTION ( nFilter := 11, ;
oBrw:aArrayData := ReadFolder(), oBrw:Refresh( .t. ), VerDoc( oBrw ) )
DEFINE BUTTON OF oWnd:oBar PROMPT "Images" CENTER ACTION ( nFilter := 2 , ;
oBrw:aArrayData := ReadFolder(), oBrw:Refresh( .t. ), VerDoc( oBrw ) )
DEFINE BUTTON OF oWnd:oBar PROMPT "Object" CENTER ACTION ( nFilter := 3 , ;
oBrw:aArrayData := ReadFolder(), oBrw:Refresh( .t. ), VerDoc( oBrw ) )
DEFINE BUTTON OF oWnd:oBar PROMPT "Dbf" CENTER ACTION ( nFilter := 4 , ;
oBrw:aArrayData := ReadFolder(), oBrw:Refresh( .t. ), VerDoc( oBrw ) )
DEFINE BUTTON OF oWnd:oBar PROMPT "All" CENTER ACTION ( nFilter := 0 , ;
oBrw:aArrayData := ReadFolder(), oBrw:Refresh( .t. ), VerDoc( oBrw ) )
DEFINE BUTTON OF oWnd:oBar PROMPT "Folder" CENTER ;
ACTION ( cDirName := cGetDir( "Select Folder", GetCurDir() + "\" ), ;
SetCurDir( cDirName ), ;
oBrw:aArrayData := ReadFolder(), oBrw:Refresh( .t. ), VerDoc( oBrw ) )
@ oWnd:oBar:nHeight,0 XBROWSE oBrw SIZE nWBrw,-oWnd:oMsgBar:nHeight ;
PIXEL OF oWnd DATASOURCE aImages COLUMNS 1 CELL LINES NOBORDER
WITH OBJECT oBrw
:aCols[ 1 ]:cHeader := "Files"
:nStretchCol := 1
:bChange := { | o | VerDoc( o ) }
:bLDblClick := { | o | LookOthers( oBrw ) }
:bClrStd := { || { If( oBrw:aRow[ 3 ] == 1, CLR_BLUE, CLR_HRED ), CLR_WHITE } }
:bKeyDown := { |n,f| if( n = VK_RETURN, Eval( oBrw:bLDblClick ), ) }
:CreateFromCode()
END
WITH OBJECT oWnd
:nWidth := ScreenWidth() * 0.6
:nHeight := ScreenHeight() * 0.6
END
@ oWnd:oBar:nHeight, nWBrw RICHEDIT5 oRTF VAR cRTF OF oWnd ;
SIZE oWnd:nWidth - (nWBrw+18), oBrw:nHeight*1.82 PIXEL NOBORDER HSCROLL
ACTIVATE WINDOW oWnd CENTERED ON INIT VerDoc( oBrw ) ;
ON PAINT ( oRTF:SetSize( oWnd:nWidth - (nWBrw+18), oBrw:nHeight-2 ) ) //ON INIT oWnd:SetControl( oRTF )
RELEASE FONT oFont
//RELEASE BRUSH oBrush
return nil
//----------------------------------------------------------------------------//
Function VerDoc( oBrw )
local nOpc := 0
local lText := .F.
if !Empty( Ascan( aFilesTxt, Upper( cFileExt( oBrw:aRow[ 2 ] ) ) ) )
nOpc := 1
endif
if Empty( nOpc )
if !Empty( Ascan( aFilesImg, Upper( cFileExt( oBrw:aRow[ 2 ] ) ) ) )
nOpc := 2
endif
endif
if Empty( nOpc )
if !Empty( Ascan( aFilesObj, Upper( cFileExt( oBrw:aRow[ 2 ] ) ) ) )
nOpc := 3
endif
endif
oRTF:SetClear()
oRTF:SelectAll()
oRTF:Del()
Do Case
Case nOpc = 1
if Upper( cFileExt( oBrw:aRow[ 2 ] ) ) <> "RTF"
lText := .T.
oRTF:SetText( MemoRead( AllTrim( oBrw:aRow[ 2 ] ) ) )
else
oRTF:LoadFromRTFFile( AllTrim( oBrw:aRow[ 2 ] ) )
endif
Case nOpc = 2
oRTF:InsertPictureFile( AllTrim( oBrw:aRow[ 2 ] ) )
Case nOpc = 3
oRTF:InsertObject( AllTrim( oBrw:aRow[ 2 ] ) + Chr(0) )
Otherwise
oRTF:LoadRTF( AllTrim( oBrw:aRow[ 2 ] ) )
EndCase
Return nil
//----------------------------------------------------------------------------//
Static Function LookOthers( oBrw )
local nOpc := 0
if !Empty( Ascan( aFilesTxt, Upper( cFileExt( oBrw:aRow[ 2 ] ) ) ) )
nOpc := 1
endif
if Empty( nOpc )
if !Empty( Ascan( aFilesImg, Upper( cFileExt( oBrw:aRow[ 2 ] ) ) ) )
nOpc := 2
endif
endif
if Empty( nOpc )
if !Empty( Ascan( aFilesObj, Upper( cFileExt( oBrw:aRow[ 2 ] ) ) ) )
nOpc := 3
endif
endif
if Empty( nOpc )
if Upper( cFileExt( oBrw:aRow[ 2 ] ) ) = "DBF"
XBrowse( oBrw:aRow[ 2 ] )
else
MsgInfo( "Format not supported", oBrw:aRow[ 2 ] )
endif
endif
Return nil
//----------------------------------------------------------------------------//
static function ReadFolder()
local aImages := {}
local aSub := { "*" }
local c
local x
local cPath := cDirName
local aDir
local aAlls := {}
AEVal( aFilesTxt, { | a | AAdd( aAlls, a ) } )
AEVal( aFilesImg, { | a | AAdd( aAlls, a ) } )
AEVal( aFilesObj, { | a | AAdd( aAlls, a ) } )
AEVal( aFilesAll, { | a | AAdd( aAlls, a ) } )
Do Case
Case nFilter = 0
aSub := { "*" }
Case nFilter = 1
aSub := { "rtf" }
Case nFilter = 11
aSub := aClone( aFilesTxt )
aSub := ADel( aSub, 1 )
ASize( aSub, Len( aSub ) - 1 )
Case nFilter = 2
aSub := aClone( aFilesImg )
Case nFilter = 3
aSub := aClone( aFilesObj )
Case nFilter = 4
aSub := { "dbf" }
EndCase
for each c in aSub
aDir := Directory( cPath + "\*." + c )
AEval( aDir, { | a | AAdd( aImages, { Lower( a[ 1 ] ), ;
Lower( TrueName( cPath + "\" + a[ 1 ] ) ), 0 } ) } )
next
For x = 1 to Len( aImages )
if !Empty( Ascan( aAlls, Upper( cFileExt( aImages[ x ][ 2 ] ) ) ) )
aImages[ x ][ 3 ] := 1
endif
Next x
ASort( aImages,,,{ | x, y | Lower( x[ 1 ] ) < Lower( y[ 1 ] ) } )
return aImages
//----------------------------------------------------------------------------//