Xbrowse - New method *SelColor*

Post Reply
Rossine
Posts: 343
Joined: Tue Oct 11, 2005 11:33 am

Xbrowse - New method *SelColor*

Post by Rossine »

Olá todos,

Segue abaixo um exemplo de como mudar a cor/fonte do browse e das colunas:

Code: Select all

// Browsing arrays using TXBrowse and change colors and fonts

#include "FiveWin.ch"
#include "hbclass.ch"
#include "xbrowse.ch"

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

function Main()

   local oDlg, oBrw
   local aSample := { { "Teste", "Teste", "Teste", "Teste", "Teste" } , ;
                      { "Teste", "Teste", "Teste", "Teste", "Teste" } , ;
                      { "Teste", "Teste", "Teste", "Teste", "Teste" } , ;
                      { "Teste", "Teste", "Teste", "Teste", "Teste" } , ;
                      { "Teste", "Teste", "Teste", "Teste", "Teste" } , ;
                      { "Teste", "Teste", "Teste", "Teste", "Teste" } , ;
                      { "Teste", "Teste", "Teste", "Teste", "Teste" } }

   override method SelFont  in   class  TXBrowse with MySelFont
   extend   class  TXBrowse with method SelColor

   DEFINE DIALOG oDlg FROM 2, 2 TO 20, 60 TITLE "right click on the listbox"

   oBrw := TXBrowse():New( oDlg )

   oBrw:SetArray( aSample )

   oBrw:nTop          := 0
   oBrw:nLeft         := 0
   oBrw:nBottom       := 100
   oBrw:nRight        := 200
   oBrw:lHScroll      := .f.
   oBrw:lVScroll      := .f.
   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW

   for n = 1 to 5
       oBrw:aCols[n]:cHeader := "Coluna " + alltrim(str(n))
   next

   oBrw:CreateFromCode()

   oDlg:oClient := oBrw

   oBrw:brclicked := { |nRow, nCol| SHOWPOPUP( oBrw, nRow, nCol ) }

   ACTIVATE DIALOG oDlg CENTERED

return nil

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

static function SHOWPOPUP( oBrw, nRow, nCol )

local oPopup, nColBrw := oBrw:MouseColPos( nCol )

menu oPopup popup
     menuitem "&Mudar cor       do Browse" action oBrw:SelColor(,, .t. )
     menuitem "&Mudar Fonte     do Browse" action oBrw:SelFont( , .f. )
     menuitem "&Mudar cor/fonte do Browse" action oBrw:SelFont( , .t. )
     separator
     menuitem "&Mudar cor       da Coluna" action oBrw:SelColor( nColbrw,, .t. )
     menuitem "&Mudar Fonte     da Coluna" action oBrw:SelFont( nColbrw, .f. )
     menuitem "&Mudar cor/fonte da Coluna" action oBrw:SelFont( nColbrw, .t. )
     separator
     menuitem "&Retornar"  action oPopup:End()
endmenu

activate popup oPopup at nRow, nCol of oBrw

return NIL

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

static function MySelFont( nSelCol, lColor )

local Self := HB_QSelf()

local oFont, n, nForeColor

DEFAULT nSelCol := 0, lColor := .F.

**define font oFont from USER 

if nSelCol = 0 
   nForeColor := ::nClrText
   oFont      := ::oFont:choose( @nForeColor )
   ::nClrText := nForeColor
   ::oFont    := oFont
   if oFont:cFaceName != "SYSTEM_FONT" 
      for n = 1 to Len( ::aCols ) 
          ::aCols[ n ]:oDataFont := oFont 
      next 
   endif 
   if lColor
      ::SelColor( , nForeColor, .F. )
   endif
else 
   nForeColor                 := Eval(::aCols[nSelCol]:bClrStd)[1]
   oFont                      := ::aCols[nSelCol]:oDataFont:choose( @nForeColor )
   ::aCols[nSelCol]:oDataFont := oFont 
   if lColor
      ::SelColor( nSelCol, nForeColor, .F. )
   endif
endif 

*::Refresh()

return nil

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

static function SelColor( nSelCol, nColorFore, lRefresh )

local Self := HB_QSelf()

local nColorBack, n

DEFAULT nSelCol := 0, lRefresh := .T.

nColorBack := choosecolor( iif( nSelCol = 0, ::nClrPane, Eval(::aCols[nSelCol]:bClrStd)[2] ) )

if nSelCol = 0 
   ::nClrPane := nColorBack
   for n = 1 to Len( ::aCols ) 
       nColorFore         := iif( nColorFore = NIL, Eval(::aCols[ n ]:bClrStd)[1], nColorFore )
       ::aCols[n]:bClrStd := &( "{ || { " + str(nColorFore) + ", " + str(nColorBack) + " } }" )
   next 
else 
   nColorFore := iif( nColorFore = NIL, Eval(::aCols[nSelCol]:bClrStd)[1], nColorFore )
   ::aCols[nSelCol]:bClrStd := &( "{ || { " + str(nColorFore) + ", " + str(nColorBack) + " } }" )
endif 

if lRefresh
   ::Refresh() 
endif

return nil

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


Antonio,

Eu encontrei um problema na classe ´TFont´no método choose(). Para você simular o problema no exemplo acima faça o seguinte:

1º) Mude a fonte do browse
2º) Mude a fonte de uma coluna qualquer, aí a fonte do browse é toda mudada também, porque ???

Peço a todos interessados que testem e me reporte possíveis erros ok ?

Obrigado,

Rossine.
Rossine
Posts: 343
Joined: Tue Oct 11, 2005 11:33 am

Post by Rossine »

Antonio,

Aproveitando o tópico, seria interessante incluir o processamento da tecla "VK_TAB" para se focar o próximo/anterior objeto dentro da xbrowse. Segue código:

Code: Select all


METHOD KeyChar( nKey, nFlags ) CLASS TXBrowse

...

      case nKey == VK_TAB .and. GetKeyState( VK_SHIFT )

           ::oWnd:GoPrevCtrl( ::hWnd )

      case nKey == VK_TAB

           ::oWnd:GoNextCtrl( ::hWnd )

      case nKey == VK_RETURN
...

Saludos,

Rossine.
Post Reply