#include "windows.ch" #include "hwgui.ch" #include "common.ch" #include "guilib.ch" #include "wvgparts.ch" #include "hbgtinfo.ch" #include "hbcompat.ch" #include "hwg_extctrl.ch" #define ID_TEXTO 300 FUNCTION Preview LOCAL oIconPrint:=HIcon():AddFile("IMG\IPRINTER2.ICO") LOCAL nWIDTH:= hb_gtInfo( HB_GTI_SCREENWIDTH ) LOCAL nHEIGHT:=hb_gtInfo( HB_GTI_SCREENHEIGHT ) LOCAL nCorFundo:=13827581 LOCAL nCorJanela:=16579836 LOCAL aTexto:={""}, nPage:=1, oPage:=1, nLoopPage:=0 LOCAL cLinha, lEject, lEscape PRIVATE oDlgReport PRIVATE nCorFonteP, nCorFundoP nCorFonteP:=nCorFonte nCorFundoP:=nCorFundo nWIDTH:= hb_gtInfo( HB_GTI_SCREENWIDTH ) nHEIGHT:=hb_gtInfo( HB_GTI_SCREENHEIGHT ) FT_FUSE( cArq ) FT_FGOTOP() DO WHILE !FT_FEOF() cLinha:=FT_FREADLN() lEject:=(Chr(12) $ cLinha) lEscape:=(Chr(27) $ cLinha) cLinha:=StrTran( cLinha, Chr(12)) // Elimina caracter EJECT cLinha:=Reformata(cLinha) IF nLoopPage <> oPage IF Empty(cLinha) hwg_DoEvents() FT_FSKIP() LOOP ENDIF nLoopPage:=oPage ENDIF aTexto[oPage]+=cLinha + Chr( 13 ) + Chr( 10 ) IF lEject AADD(aTexto,"") oPage++ ENDIF hwg_DoEvents() FT_FSKIP() ENDDO FT_FUSE() IF Empty(aTexto[oPage]) hb_ADel( aTexto, oPage, .T. ) oPage-- ENDIF cText:=aTexto[ nPage ] PREPARE FONT oFont NAME "Arial" WIDTH 0 HEIGHT 0 WEIGHT -10 oFont2:=HFont():Add( "Courier New" ,0,-13, 0,,, ) oFont3:=HFont():Add( "Arial" ,6 ) hwg_SetToolTipBalloon(.T.) INIT DIALOG oDlgReport TITLE "Preview de Relatório" ; ICON oIconPrint ; AT 0,0 SIZE nWIDTH-50,nHEIGHT-50 ; CLIPPER; FONT oFont ; COLOR nCorJanela ; STYLE DS_CENTER + WS_SYSMENU + WS_VISIBLE ; ON INIT {| oDlgReport | oDlgReport:bInit:=btnSair} @ 127,019 RichEdit oEdit TEXT cText SIZE nWIDTH-192,nHEIGHT-130 ; OF oDlgReport ID ID_TEXTO ; COLOR nCorFonteP ; BACKCOLOR nCorFundoP ; STYLE WS_HSCROLL+WS_VSCROLL+ES_LEFT+ES_MULTILINE+ES_READONLY ; ON GETFOCUS {|| TopoDoc()}; FONT oFont2 //ON OTHERMESSAGES {|This,m,wp,lp| richeditProc( this, m,wp, lp ) } oEdit:bOther:={|This,m,wp,lp| richeditProc( this, m,wp, lp ) } @ 006,220 BUTTONEX cmd5 ; CAPTION "Seguinte" ; ON CLICK { || nPage:= PaginaSeguinte( oPage, nPage, aTexto, oDlgReport ) } ; SIZE 115, 40 ; ICON oIconSeguinte:handle ; TOOLTIP 'Clique aqui para ir para página seguinte.' @ 006,620 BUTTONEX btnSair ; CAPTION "Sair" ; ON CLICK { || hwg_EndDialog()} ; SIZE 115, 40 ; ICON oIconSair:handle ; TOOLTIP 'Clique aqui para sair.' ADD STATUSEX oStatus TO oDlgReport PARTS 280,90,90,120,0 FONT oFont3 ON INIT {|This| Status(This,aTexto) } oDlgReport:Activate(.F.) // Parâmetro .T. = NOMODAL, .F. ou () = MODAL RETURN Nil STATIC FUNCTION TopoDoc() hwg_SendMessage(oEdit:Handle, WM_VSCROLL ,SB_TOP,0) hwg_SendMessage(oEdit:Handle, EM_SETSEL ,0,0) RETURN .T. STATIC FUNCTION RichEditProc( oEdit, Msg, wParam, lParam ) LOCAL nPos, nPos1, nPos2, nVirtCode //nVirtCode := wParam //IF Msg == WM_KEYUP //ENDIF IF Msg == WM_KEYDOWN hwg_msginfo("") nVirtCode := wParam IF nVirtCode == VK_ESCAPE //hwg_KEYB_EVENT( VK_ESCAPE ) ENDIF IF nVirtCode == VK_F3 //Texto_Encontrado(oEdit) ENDIF nPos :=hwg_SendMessage( oEdit:Handle, EM_GETSEL, 0, 0 ) nPos1 :=hwg_Loword( nPos ) + 1 nPos2 :=hwg_Hiword( nPos ) + 1 nLinha :=hwg_SendMessage(oEdit:Handle, EM_LINEFROMCHAR, -1, 0) + 1 nColuna:=nPos1 - hwg_SendMessage( oEdit:Handle, EM_LINEINDEX, -1, 0 ) // hwg_WriteStatus( oDlgReport,2,'Lin: '+LTrim(Str(nLinha,5))) hwg_WriteStatus( oDlgReport,3,'Col: '+LTrim(Str(nColuna,3))) oEdit:Refresh() ENDIF RETURN -1 STATIC FUNCTION PaginaSeguinte(oPage, nPage, aTexto, oDlgReport ) LOCAL oDlg:=hwg_GetModalHandle() nPage := ++ nPage IF nPage > oPage ; nPage := oPage ; ENDIF cTexto:=aTexto[ nPage ] IF Empty(cTexto) cTexto:="" ENDIF hwg_SetDlgItemText( oDlg, ID_TEXTO, WIN_OEMTOANSI(cTexto) ) hwg_WriteStatus( oDlgReport,4,'Página: '+LTrim(Str(nPage,6))+" de "+LTrim(Str(Len(aTexto),6))) RETURN nPage STATIC FUNCTION Reformata(cTexto) LOCAL cText:=cTexto cText:=StrTran(cText,Chr(27)+"P"+Chr(15)) cText:=StrTran(cText,Chr(12),Chr(13)+Chr(13)) cText:=StrTran(cText,Chr(27)+"P") cText:=StrTran(cText,Chr(27)+Chr(77)+Chr(15)) cText:=StrTran(cText,Chr(27)+Chr(77)+Chr(18)) cText:=StrTran(cText,Chr(27)+Chr(80)+Chr(18)) cText:=StrTran(cText,Chr(15)) cText:=StrTran(cText,Chr(18)) RETURN cText STATIC FUNCTION Status(This,aTexto) This:settextpanel(2,'Lin: '+LTrim(Str(1,5))) This:settextpanel(3,'Col: '+LTrim(Str(1,3))) This:settextpanel(4,'Página: '+LTrim(Str(1,5))+" de "+LTrim(Str(Len(aTexto),5))) This:settextpanel(5,'Antes de imprimir, pense em sua responsabilidade com o meio ambiente.') //hwg_WriteStatus(This,2,'Lin: '+LTrim(Str(1,5))) //hwg_WriteStatus(This,3,'Col: '+LTrim(Str(1,3))) //hwg_WriteStatus(This,4,'Página: '+LTrim(Str(1,5))+" de "+LTrim(Str(Len(aTexto),5))) //hwg_WriteStatus(This,5,'Antes de imprimir, pense em sua responsabilidade com o meio ambiente.') RETURN Nil