Also for Tree on the Xbrowse for Mr Rao

Also for Tree on the Xbrowse for Mr Rao

Postby Silvio » Thu Feb 11, 2010 8:53 am

Dear Mr. Rao,
After the last sample I try to insert another component but I think I must use another archive to insert the hardaware type because I have many component to insert :

Computer
Monitor
Keyboard
Mouse
Printer
Swicth
Scanner
Pocket
Camera
Projector

the code
Code: Select all  Expand view
function Main()

   local oWnd, oBrw ,oBold

   USE HARDWARE
   INDEX ON Field->LABORATORY TO LABS
   SET ORDER TO "LABS"
   GO TOP
    DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-12 BOLD
   DEFINE WINDOW oWnd TITLE "SAMPLE DBF shown as a tree with XBrowse width images"

   @ 2, 0 XBROWSE oBrw OF oWnd LINES CELL

   oBrw:SetTree( BuildTree(), {"TREE_LAB", "TREE_AULE", 'TREE_HARD' } )

   oBrw:lKinetic = .F.


WITH OBJECT  oBrw:aCols[ 1 ]
      :AddResource( 'TREE_LAPTOP' )
      :AddResource( 'TREE_PRINTERS' )
      :AddResource( 'TREE_MONITOR' )
      :AddResource( 'TREE_KEYBOARD' )
      :AddResource( 'TREE_SWITCH' )
      :AddResource( 'TREE_MOUSE' )
      :AddResource( 'TREE_POCKET' )
      :AddResource( 'TREE_SCANNER' )

      :bBmpData := { ||  If(  oBrw:oTreeItem:oTree == nil, ;
              HB_DeCode( Trim(  oBrw:oTreeItem:cPrompt ), 'NOTEBOOK', 4, 'PRINTERS', 5, ;
             (HB_DeCode( Trim(  oBrw:oTreeItem:cPrompt ), 'MONITOR', 6, 'KEYBOARD', 7, ;
             (HB_DeCode( Trim(  oBrw:oTreeItem:cPrompt ), 'SWITCH', 8, 'MOUSE', 9, ;
             (HB_DeCode( Trim(  oBrw:oTreeItem:cPrompt ), 'POCKET', 10, 'SCANNER', 11, ;
             3)))))) ), ;
             If( oBrw:oTreeItem:lOpened, 1, 2 ) ) }
   END

   ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 1 ] HEADER "MARCA"
   ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 2 ] HEADER "MODELLO"
   ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 3 ] HEADER "NUM INVENTARIO"

    oBrw:lFooter      := .t.

   oBrw:nMarqueeStyle = MARQSTYLE_HIGHLROW
   oBrw:nStretchCol = STRETCHCOL_LAST

      oBrw:nRowHeight  :=40
    oBrw:nHeaderHeight  := 36



    oBrw:nRowDividerStyle := 0
   * oBrw:nColDividerStyle := 0

  // If different fonts are required on the basis of oItem:nLevel
   AEval( oBrw:aCols, { |oCol| oCol:oDataFont := { || If( oBrw:oTreeItem:nLevel == 1, oBold, oBrw:oFont ) } } )

    ntotal:= (alias())->(OrdKeyCount())

   oBrw:aCols[ 1 ]:cFooter := "Total"

   oBrw:aCols[ 2 ]:cFooter := ntotal


    AEval( oBrw:aCols, { |oCol| oCol:oFooterFont := oBold } )


    oBrw:MakeTotals()
   oBrw:CreateFromCode()

   oBrw:aCols[ 1 ]:cHeader = "LABORATORY     HARDWARE TYPE"

   oWnd:oClient = oBrw

    // Create ButtonBar
   BtnBar( oBrw )    // Commn ButtonBar for all sample Browses

   DEFINE BUTTON OF oWnd:oBar ;
      RESOURCE "EXPAND" TOP PROMPT "Expand" ;
      ACTION ( oBrw:oTree:Expand(), oBrw:Refresh(), oBrw:SetFocus() )

   DEFINE BUTTON OF oWnd:oBar ;
      RESOURCE "COLLAPS" TOP PROMPT "Collapse" ;
      ACTION ( oBrw:oTree:Collapse(), oBrw:Refresh(), oBrw:SetFocus() )

   SET MESSAGE OF oWnd TO oWnd:cCaption 2007

   ACTIVATE WINDOW oWnd

return nil

static function BuildTree()

   local oTree, cState

   TREE oTree
      while ! Eof()
         if Empty( cState )
            _TreeItem( HARDWARE->LABORATORY ):Cargo := { Space( 20 ), Space( 20 ), Space( 20 ) }
            TREE
            cState = HARDWARE->LABORATORY
         else
            if cState != HARDWARE->LABORATORY
               ENDTREE
               cState = HARDWARE->LABORATORY
               _TreeItem( HARDWARE->LABORATORY ):Cargo := { Space( 20 ), Space( 20 ), Space( 20 ) }
               TREE
            endif
         endif
         if HARDWARE->LABORATORY == cState
            _TreeItem( HARDWARE->Type ):Cargo := { HARDWARE->marca, HARDWARE->modello, HARDWARE->CODICE }
         endif
         SKIP
      enddo
      ENDTREE
   ENDTREE

   GO TOP

return oTree

 



as you can see on this picture

Image

I add a code but I thinked perhaps there is another method or we can insert another dbf component.dbf ( code, description, images)





How I can make ?
Best Regards, Saludos

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

Re: Also for Tree on the Xbrowse for Mr Rao

Postby nageswaragunupudi » Thu Feb 11, 2010 11:42 am

Usage of HB_Decode:
Code: Select all  Expand view

             HB_DeCode( Trim(  oBrw:oTreeItem:cPrompt ), ;
                   'NOTEBOOK', 4, 'PRINTERS', 5, 'MONITOR', 6, 'KEYBOARD', 7,  ;
                   'SWITCH', 8,  'MOUSE', 9,  'POCKET', 10, 'SCANNER', 11, 3 )
 

When there are so many items, better you keep the items in an array and use AScan.

Code: Select all  Expand view

local aItems := { 'COMPUTER','NOTEBOOK', 'PRINTERS', 'MONITOR', ;
                  'KEYBOARD', 'SWITCH', 'MOUSE', 'POCKET', 'SCANNER' }

< .... other code .. >

      :bBmpData := { ||  If(  oBrw:oTreeItem:oTree == nil, ;
             AScan( aItems, Trim(  oBrw:oTreeItem:cPrompt ) ) + 2,
             If( oBrw:oTreeItem:lOpened, 1, 2 ) ) }

 

Basically I suggested a code for setting bBmpData. How best to derive the bitmap number based on the data is to be decided by you.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10627
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Also for Tree on the Xbrowse for Mr Rao

Postby Silvio » Thu Feb 11, 2010 12:43 pm

I MADE ALSO THIS TO SAVE ON A EXTERN DBF THE BITMAPS


USE TABLE ALIAS TABLE
TABLE->(DbSeek("G"))
DO WHILE TABLE->CveTab="H" .AND. !TABLE->(EoF())
AAdd(ahardBmp,TABLE->Bitmap)
TABLE->(DbSkip())
ENDDO
TABLE->(DbCloseArea())


....

WITH OBJECT oBrw:aCols[ 1 ]

AEval(ahardBmp, { |cBmpFile| oCol:AddBmpFile(cBmpFile)}


BUT THERE IS SOMETHING OF WRONG BECAUSE IT MAKE ERROR, I DON'T KNOW
Best Regards, Saludos

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

Re: Also for Tree on the Xbrowse for Mr Rao

Postby Silvio » Thu Feb 11, 2010 4:51 pm

Nages,
I made

Code: Select all  Expand view
local aItems  :={}
 local ahardBmp:={}


USE TABLE ALIAS TABLE
   INDEX ON TABLE->CODE TO CODETABLE
   TABLE->(DbSeek("H"))
   DO WHILE TABLE->CveTab="H" .AND. !TABLE->(EoF())
        AAdd(aItems,TRIM(TABLE->DESCRI))
       AAdd(ahardBmp,TABLE->Bitmap)
       TABLE->(DbSkip())
    ENDDO
     TABLE->(DbCloseArea())



 USE HARDWARE
   INDEX ON Field->LABORATORY TO LABS
   SET ORDER TO "LABS"
   GO TOP
    DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-12 BOLD
   DEFINE WINDOW oWnd TITLE "SAMPLE DBF shown as a tree with XBrowse width images"

   @ 2, 0 XBROWSE oBrw OF oWnd LINES CELL



     oBrw:SetTree( BuildTree(), {"TREE_LAB", "TREE_AULE", 'TREE_HARD' } )



 WITH OBJECT  oBrw:aCols[ 1 ]


AEval(ahardBmp, { |cBmpFile| :AddBmpFile(cBmpFile)} )

 :bBmpData := { ||  If(  oBrw:oTreeItem:oTree == nil, ;
             AScan( aItems, Trim(  oBrw:oTreeItem:cPrompt ) ) + 2, ;
             If( oBrw:oTreeItem:lOpened, 1, 2 ) ) }

END

ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 1 ] HEADER "MARCA"
   ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 2 ] HEADER "MODELLO"
   ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 3 ] HEADER "NUM INVENTARIO"


   ACTIVATE WINDOW oWnd

return nil
 



why not run ?
Best Regards, Saludos

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

Re: Also for Tree on the Xbrowse for Mr Rao

Postby stefano » Mon May 31, 2010 9:30 pm

You can also change the bitmaps of the first tree ?

es
lab2 ... 1.bmp
lab3 ... 2.bmp
segreteria ... 3.bmp
FWH 14.11 + xHarbour + bcc582
stefano
 
Posts: 80
Joined: Tue Mar 25, 2008 9:03 pm
Location: ITALIA

Re: Also for Tree on the Xbrowse for Mr Rao

Postby nageswaragunupudi » Tue Jun 01, 2010 12:53 am

stefano wrote:You can also change the bitmaps of the first tree ?

es
lab2 ... 1.bmp
lab3 ... 2.bmp
segreteria ... 3.bmp

Yes
Provide an array of resources in the second parameter of SetTree(...) method and then reassign oCol:bBmpData with your own codeblock to select the bitmap you want.
The default codeblock is
Code: Select all  Expand view
oCol:bBmpData   := { || If( ::oTreeItem:oTree == nil, aBmp[ 3 ], If( ::oTreeItem:lOpened, aBmp[ 1 ], aBmp[ 2 ] ) ) }

You can provide your own codeblock to show the bitmap you want conditionally.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10627
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Silvio.Falconi and 123 guests