color on a cell

color on a cell

Postby Silvio » Wed Jan 07, 2009 1:27 am

I am creating an application for management of motor vehicles.
I want on xbrowse on fiels color show the real color I selected
see the picture pls.
Image
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: color on a cell

Postby Daniel Garcia-Gil » Wed Jan 07, 2009 4:50 am

hi silvio...
i hope this help you

Code: Select all  Expand view
#include "FiveWin.ch"
#include "xbrowse.ch"

// xbrowse imagen button get

function main()

local oDlg, oBrw
local aArray := {}
local uVal
local nI
local oGet
local nWdGet := 0

for nI = 1 to 20
aadd( aArray, { StrZero(nI,2),;
                        "Row:"+StrZero(nI,2)+" Col:02",;
                        "Row:"+StrZero(nI,2)+" Col:03",;
                        "Row:"+StrZero(nI,2)+" Col:04",;
                        "Row:"+StrZero(nI,2)+" Col:05",;
                        "Row:"+StrZero(nI,2)+" Col:06" } )
next

DEFINE DIALOG oDlg Title "Test xBrowse " size 700,300


oBrw:= txbrowse():new( oDlg )
oBrw:nRowHeight := 25
oBrw:nColDividerStyle := LINESTYLE_BLACK
oBrw:nRowDividerStyle := LINESTYLE_BLACK
oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW
oBrw:SetArray( aArray )
oBrw:CreateFromCode()

oBrw:aCols[ 2 ]:bClrStd := {|o| ChangeColor( o, oBrw ) }
oBrw:aCols[ 2 ]:bClrSelFocus := {|o| ChangeColor( o, oBrw ) }



oDlg:oClient := oBrw

ACTIVATE DIALOG oDlg center on init oDlg:Resize()

return nil


function ChangeColor( oCol, oBrw )
local aClrs := eval( oBrw:bClrStd )

   
   DO CASE
      CASE oBrw:aRow[ 1 ] == "01"
         aClrs[ 2 ] := CLR_GREEN
      CASE oBrw:aRow[ 1 ] == "02"
         aClrs[ 2 ] := CLR_YELLOW
      CASE oBrw:aRow[ 1 ] == "03"
         aClrs[ 2 ] := CLR_BLUE
      CASE oBrw:aRow[ 1 ] == "04"
         aClrs[ 2 ] := CLR_CYAN
      OTHERWISE
         aClrs[ 2 ] := CLR_HRED
   ENDCASE
   
return aClrs
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: color on a cell

Postby Silvio » Wed Jan 07, 2009 8:04 am

Thanks you are my great friend!!
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: color on a cell

Postby Silvio » Wed Jan 07, 2009 8:08 am

How I can select only red color cell with mouse ?
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: color on a cell

Postby Daniel Garcia-Gil » Wed Jan 07, 2009 5:38 pm

please test this change the class

new data in txbrowse class
DATA bSelected

Change Method Select

Code: Select all  Expand view
METHOD Select( nOperation ) CLASS TXBrowse

   local uBook, uCurRow, uOldRow, uTemp
   local aTemp
   local nAt, nLen
   local lRefresh

   if ::nMarqueeStyle != MARQSTYLE_HIGHLROWMS
      return nil
   endif
   

    if VALTYPE ( Eval( ::bSelected, Self ) ) != "L" //daniel
       msgalert( "Invalid CodeBlock ::bSelected", "FiveWin, Class TXBrowse" ) //daniel
       return nil //daniel
    endif //daniel

   DEFAULT nOperation := 1
   do case
   case nOperation ==   0 // delete all
      if Len( ::aSelected ) == 1 .and.  Eval( ::bBookMark ) == ::aSelected[ 1 ]
         lRefresh := .f.
      else
         lRefresh := .t.
      endif
      ::aSelected   := {}

      if ! Empty( ::nSaveMarq )
         ::nMarqueeStyle   := ::nSaveMarq
         ::nSaveMarq       := nil
      endif

      if lRefresh
         // ::lRefreshOnlyData := .t.
         ::GetDC()
         ::Super:Refresh( .t. ) // ::Paint()
         ::ReleaseDC()
      endif

   case nOperation == 1 .or. ( Len( ::aSelected ) == 0 .and. nOperation != 4 )// Add current
      uBook := Eval( ::bBookMark )
      nAt   := Ascan( ::aSelected, uBook )
      if nAt == 0 .and. Eval( ::bSelected, Self ) //daniel
         Aadd( ::aSelected, uBook )
         ::DrawLine( .t. )
      endif

   case nOperation == 2 // Swap key (Ctrl+LClick)
      uBook := Eval( ::bBookMark )
      nAt   := Ascan( ::aSelected, uBook )
      if nAt > 0
         ::DrawLine( .f. )
         ::aSelected[ nAt ] := Atail( ::aSelected )
         Asize( ::aSelected, Len( ::aSelected ) - 1 )
      else
         if  Eval( ::bSelected, Self ) //daniel
         Aadd( ::aSelected, Eval( ::bBookMark ))
         ::DrawLine( .t. )                        
        endif                                             //daniel
      endif

   case nOperation == 3 // Shift & lclick
      uBook   := Eval( ::bBookMark )
      uCurRow := ::KeyNo()
      Eval( ::bBookMark,  Atail( ::aSelected ) )
      uOldRow := ::KeyNo()
      if uOldRow != uCurRow
         ::aSelected := { Atail( ::aSelected ) }
         if uCurRow > uOldRow
            CursorWait()
            do while ( uTemp := Eval( ::bBookMark ) ) != uBook .and. ! ::Eof()
               If Ascan( ::aSelected, uTemp ) == 0 .and. Eval( ::bSelected, Self ) //daniel
                  Aadd( ::aSelected, uTemp )
               Endif
               ::Skip( 1 )          // Eval( ::bSkip, 1 )
            enddo
            CursorArrow()
         else
            CursorWait()
            do while ( uTemp := Eval( ::bBookMark ) ) != uBook .and. ! ::Bof()
               If Ascan( ::aSelected, uTemp ) == 0 .and. Eval( ::bSelected, Self ) //daniel
                  Aadd( ::aSelected, uTemp )
               endif
               ::Skip( -1 )         // Eval( ::bSkip, -1 )
            enddo
            CursorArrow()
         endif
         if Eval( ::bSelected, Self ) //daniel
            Aadd( ::aSelected, uBook )
          endif
         Eval( ::bBookMark, uBook )
         // ::lRefreshOnlyData := .t.
         ::GetDC()
         ::Paint()
         ::ReleaseDC()

      else
         Eval( ::bBookMark, uBook )
      endif

   case nOperation == 4 // Select all
      uBook       := Eval( ::bBookMark )
      ::aSelected := Array( ::KeyCount() )
      nAt         := 1
      nLen        := ::nLen
      aTemp       := ::aSelected
      CursorWait()
      Eval( ::bGotop )
      do while nAt <= nLen //.and. !Eval( ::bEof )
          if Eval( ::bSelected, Self ) //daniel
           aTemp[ nAt++ ] := Eval( ::bBookMark )
         endif
         ::Skip( 1 )             //Eval( ::bSkip, 1 )
      enddo
      Eval( ::bBookMark, uBook )
      CursorArrow()
      // ::lRefreshOnlyData := .t.
      ::GetDC()
      ::Paint()
      ::ReleaseDC()

   end case

return nil


now Test code

Code: Select all  Expand view
#include "FiveWin.ch"
#include "xbrowse.ch"

// xbrowse imagen button get

function main()

local oDlg, oBrw
local aArray := {}
local uVal
local nI
local oGet
local nWdGet := 0

for nI = 1 to 20
aadd( aArray, { StrZero(nI,2),;
                        "Row:"+StrZero(nI,2)+" Col:02",;
                        "Row:"+StrZero(nI,2)+" Col:03",;
                        "Row:"+StrZero(nI,2)+" Col:04",;
                        "Row:"+StrZero(nI,2)+" Col:05",;
                        "Row:"+StrZero(nI,2)+" Col:06" } )
next

DEFINE DIALOG oDlg Title "Test xBrowse III " size 700,300


oBrw:= txbrowse():new( oDlg )
oBrw:nRowHeight := 25
oBrw:nColDividerStyle := LINESTYLE_BLACK
oBrw:nRowDividerStyle := LINESTYLE_BLACK
oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROWMS //MARQSTYLE_HIGHLCELL //
oBrw:SetArray( aArray )
oBrw:CreateFromCode()
oBrw:bSelected := {| o | if( ChangeColor( o, oBrw )[ 2 ] == CLR_HRED, .t., .f.) }


oBrw:aCols[ 2 ]:bClrStd := {|o| ChangeColor( o, oBrw ) }
oBrw:aCols[ 2 ]:bClrSelFocus := {|o| ChangeColor( o, oBrw ) }



oDlg:oClient := oBrw

ACTIVATE DIALOG oDlg center on init oDlg:Resize()

return nil


function ChangeColor( oCol, oBrw )
local aClrs := eval( oBrw:bClrStd )

   
   DO CASE
      CASE oBrw:aRow[ 1 ] == "01"
         aClrs[ 2 ] := CLR_GREEN
      CASE oBrw:aRow[ 1 ] == "02"
         aClrs[ 2 ] := CLR_YELLOW
      CASE oBrw:aRow[ 1 ] == "03"
         aClrs[ 2 ] := CLR_BLUE
      CASE oBrw:aRow[ 1 ] == "04"
         aClrs[ 2 ] := CLR_CYAN
      OTHERWISE
         aClrs[ 2 ] := CLR_HRED
   ENDCASE
   
return aClrs
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: color on a cell

Postby Silvio » Wed Jan 07, 2009 11:15 pm

I try it but not run ok
if I click the buttons of mouse it not make anything
How you think it run ?
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: color on a cell

Postby Silvio » Wed Jan 07, 2009 11:20 pm

Sorry perhaps I think I not explain you
look the test you made ...
I wish for a sample click on second column with the mouse from second row and pressing a button of mouse select the cells to six row and modify the color into yellow

I hope you understand me
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: color on a cell

Postby Daniel Garcia-Gil » Mon Jan 12, 2009 2:33 am

please review this sample
for popmenu use right button

Code: Select all  Expand view
#include "FiveWin.ch"
#include "xbrowse.ch"

// xbrowse imagen button get

static aCellSelected

function main()

local oDlg, oBrw
local aArray := {}
local uVal
local nI
local oGet, oBtn
local nWdGet := 0

for nI = 1 to 20
aadd( aArray, { StrZero(nI,2),;
                        SPACE( 5 ),;
                        SPACE( 5 ),;
                        SPACE( 5 ),;
                        SPACE( 5 ),;
                        SPACE( 5 ),;
                        SPACE( 5 ),;
                        SPACE( 5 ),;
                        SPACE( 5 ),;
                        SPACE( 5 ),;
                        SPACE( 5 ),;
                        SPACE( 5 ),;
                        SPACE( 5 ) } )
next

DEFINE DIALOG oDlg Title "Test xBrowse III " size 700,300


oBrw:= txbrowse():new( oDlg )
oBrw:nRowHeight := 25
oBrw:nColDividerStyle := LINESTYLE_BLACK
oBrw:nRowDividerStyle := LINESTYLE_BLACK
oBrw:nMarqueeStyle := MARQSTYLE_HIGHLCELL //MARQSTYLE_HIGHLROWMS //
oBrw:SetArray( aArray )
oBrw:CreateFromCode()


AEVAL( oBrw:aCols, { |o| o:bPopUp := { |o| ColMenu( o ) } } )

AEval( oBrw:aCols, { | oCol | oCol:bClrStd := {| | ChangeColor( oBrw ) } }, 2 )

for nI = 2 to len( oBrw:aCols )
   oBrw:aCols[ nI ]:bClrStd := GenCodeColor( oBrw, nI )
next
   

oDlg:oClient := oBrw

ACTIVATE DIALOG oDlg center on init oDlg:Resize()

return nil

Function GenCodeColor( oBrw, nI )
return {|| ChangeColor( oBrw, nI ) }

function ChangeColor( oBrw, n )
local aClrs := { CLR_BLACK, GetSysColor( 5 )}
local j
local bClrStd

   DO CASE
      CASE oBrw:aRow[ n ] == space( 4 )
         aClrs := { CLR_HRED, CLR_HRED }
      CASE oBrw:aRow[ n ] == space( 3 )
         aClrs := { CLR_BLUE, CLR_BLUE }
      CASE oBrw:aRow[ n ] == SPACE( 5 )
         aClrs := { CLR_WHITE, CLR_WHITE }
   ENDCASE
   
   
return aClrs

   
static function ColMenu( ocol )

   local oPop

   MENU oPop POPUP 2007
      menuitem "Selected" action( oCol:Value( space( 3 ) ), oCol:oBrw:Refresh() )
      menuitem "Unseleced" action( oCol:Value(space( 5 ) ), oCol:oBrw:Refresh() )
      menuitem "Active" action( oCol:Value( SPACE( 4 ) ), oCol:oBrw:Refresh() )
      
   ENDMENU

return oPop
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 72 guests