FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Also for Tree on the Xbrowse for Mr Rao
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM

Also for Tree on the Xbrowse for Mr Rao

Posted: Thu Feb 11, 2010 08: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 (fw): Select all Collapse
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



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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Also for Tree on the Xbrowse for Mr Rao

Posted: Thu Feb 11, 2010 11:42 AM
Usage of HB_Decode:
Code (fw): Select all Collapse
             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 (fw): Select all Collapse
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
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM

Re: Also for Tree on the Xbrowse for Mr Rao

Posted: 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
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM

Re: Also for Tree on the Xbrowse for Mr Rao

Posted: Thu Feb 11, 2010 04:51 PM
Nages,
I made

Code (fw): Select all Collapse
 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
Posts: 80
Joined: Tue Mar 25, 2008 09:03 PM

Re: Also for Tree on the Xbrowse for Mr Rao

Posted: Mon May 31, 2010 09: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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Also for Tree on the Xbrowse for Mr Rao

Posted: 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 (fw): Select all Collapse
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

Continue the discussion