FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Sub Niveles en Treeview ( SOLUCIONADO )
Posts: 625
Joined: Wed Mar 14, 2007 06:49 PM
Sub Niveles en Treeview ( SOLUCIONADO )
Posted: Tue Nov 03, 2015 04:11 AM
Saludos a todos:

Estoy trabajando en base a la idea del Editor de Recursos RC de Fivewin, lo ando retocando un poco pero estoy detenido con el uso del control TTreeView en el uso de SubMenus, necesito saber como obtener el numero de item seleccionado, en este ejemplo se muestran 12, pero solo me indica el numero en el item raiz (0) y del primer nivel del item (1), para poder obtener la ubicación desde de origen del recurso con la función StrToken(oTxtFile:cLine, 3) desde el archivo.RC

New BITMAP "Z:\FWH\bitmaps\32x32\new.bmp"
New2 BITMAP "Z:\FWH\bitmaps\16x16\new.bmp"
Dialog BITMAP "Z:\FWH\bitmaps\16x16\form.bmp"
DlgMask BITMAP "Z:\FWH\bitmaps\16x16\frmmask.bmp"




Les dejo el archivo fuente y el ejemplo para que puedan darle una revisada..

http://www.mediafire.com/download/scgq5advd3nia0z/RcEdit.zip

Saludos..
Soluciones y Diseño de Software
Damos Soluciones...

I.S.C. Victor Daniel Cuatecatl Leon
Director y Diseñador de Proyectos

http://www.soldisoft.unlugar.com
http://www.sisa.unlugar.com
danyleon82@hotmail.com
www.facebook.com/victordaniel.cuatecatlleon
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Sub Niveles en Treeview
Posted: Tue Nov 03, 2015 11:59 AM

Victor,

Prueba con:

oTree:GetSelected()

devuelve el item seleccionado en el treeview

Tienes un ejemplo de uso en FWH\samples\classtree.prg

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 625
Joined: Wed Mar 14, 2007 06:49 PM
Re: Sub Niveles en Treeview
Posted: Tue Nov 03, 2015 01:15 PM
Maestro Antonio:

Así es como lo estoy probando en el ejemplo que envie, pero solo devuelve el numero del primer nivel:

Code (fw): Select all Collapse
IF UPPER( StrToken( oTxtFile:cLine, 2 ) ) == "ICON"
            AADD(aIcoItem,ALLTRIM(StrToken(oTxtFile:cLine, 3)))
            IF oIcoItem == Nil
               oIcoItem = oTree:Add("ICONOS",3)
               oIcoItem:Add( StrToken( oTxtFile:cLine, 1 ), 12, {|| oGet:VarPut(aIcoItem[Nivel()]), oGet:Refresh() })
            ELSE
               oIcoItem:Add( StrToken( oTxtFile:cLine, 1 ), 12, {|| oGet:VarPut(aIcoItem[Nivel()]), oGet:Refresh() })
            ENDIF
ENDIF

STATIC FUNCTION Nivel()

LOCAL oItem:= oTree:GetSelected()
   MSGInfo( "Item Numero: " + STR( oItem:ItemLevel() ) )
      
RETURN oItem:ItemLevel()


Pero necesito saber en que numero de subitem estoy en base al contenido de archivo .rc para poder mostrar el texto en el get a partir de un array de contenidos que ya fue creado.

Alguna idea..? gracias.
Soluciones y Diseño de Software
Damos Soluciones...

I.S.C. Victor Daniel Cuatecatl Leon
Director y Diseñador de Proyectos

http://www.soldisoft.unlugar.com
http://www.sisa.unlugar.com
danyleon82@hotmail.com
www.facebook.com/victordaniel.cuatecatlleon
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Sub Niveles en Treeview
Posted: Tue Nov 03, 2015 01:43 PM

Por si sirviera:

Hace años que no toco nada de tree. Pero en aquel tiempo recuerdo que modifique la clase para añadir una Data de usuario donde almacenar la informacion necesaria y evitarme el tener que extraerla de los item padre.
Se trataria, pues que en el momento de la carga del tree, recoger en esa data la informacion necesaria y asi evitar recurrir a buscar en otros niveles. Con aquel cambio todo el trabajo posterior con el tree se me hizo mas facil.

Es una vaga idea que me queda de aquello, solo por si servia.

Saludos.

Posts: 1364
Joined: Wed Jun 21, 2006 12:39 AM
Re: Sub Niveles en Treeview
Posted: Tue Nov 03, 2015 03:57 PM

Puedes usar la data 'cargo' para almacenar lo que quieras, entre ellos un array con los niveles de profundidad de cada elemento.

Saludos

Posts: 625
Joined: Wed Mar 14, 2007 06:49 PM
Re: Sub Niveles en Treeview
Posted: Tue Nov 03, 2015 06:43 PM
Saludos de Nuevo y gracias por su colaboración:

La idea es obtener el numero de item seleccionado de un item padre, he intentado lo que me han comentado sin exito, solo logro obtener el numero del primer subitem, más no así de los que estan acontinuación, el número de items esta armado conforme este estructurado el archivo .rc



Si alguien más tiene otras ideas se agradece..

Gracias,..
Soluciones y Diseño de Software
Damos Soluciones...

I.S.C. Victor Daniel Cuatecatl Leon
Director y Diseñador de Proyectos

http://www.soldisoft.unlugar.com
http://www.sisa.unlugar.com
danyleon82@hotmail.com
www.facebook.com/victordaniel.cuatecatlleon
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Sub Niveles en Treeview
Posted: Tue Nov 03, 2015 07:11 PM

Hola
Has mirado tu mail?

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 625
Joined: Wed Mar 14, 2007 06:49 PM
Re: Sub Niveles en Treeview
Posted: Tue Nov 03, 2015 07:36 PM
Cristobal:

Revisado y verificado, es presisamente lo que necesito..

Muchas gracias..

Dejo aqui el código que complementas para que le pueda servir a alguien más..

Code (fw): Select all Collapse
#Include "FiveWin.ch"

STATIC oImageList,oTree,oFile,cSave,lOpen,oGet,oTxt

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

FUNCTION Main(cFile)

LOCAL oDlg,oIco,oBtn1,oBtn2,oBtn3,oBtn4,oCur
LOCAL cOrigen:= ""

lOpen:= .F.
    
     DEFINE CURSOR oCur RESOURCE "MANO"
     DEFINE ICON   oIco RESOURCE "00"
     DEFINE DIALOG oDlg RESOURCE "EDITOR" TITLE "Editor de Recursos RC" ICON oIco
   
   REDEFINE SAY    oFile  ID 201 OF oDlg
   
   oImageList:= TImageList():New(24,24)             
 
   oImageList:Add(TBitmap():DEFINE("RCFILE1",,oDlg),   TBitmap():DEFINE("RCFILE2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("BITMAP1",,oDlg),   TBitmap():DEFINE("BITMAP2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("DIALOG1",,oDlg),   TBitmap():DEFINE("DIALOG2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("ICON1",,oDlg),     TBitmap():DEFINE("ICON2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("SPEAKER1",,oDlg),  TBitmap():DEFINE("SPEAKER2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("VIDEO1",,oDlg),    TBitmap():DEFINE("VIDEO2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("CURSOR1",,oDlg),   TBitmap():DEFINE("CURSOR2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("CUSTOM1",,oDlg),   TBitmap():DEFINE("CUSTOM2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("MENU1",,oDlg),     TBitmap():DEFINE("MENU2",,oDlg))  
   oImageList:Add(TBitmap():DEFINE("MANIFEST1",,oDlg), TBitmap():DEFINE("MANIFEST2",,oDlg))
   
   oImageList:Add(TBitmap():DEFINE("BMP1",,oDlg), TBitmap():DEFINE("BMP2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("DLG1",,oDlg), TBitmap():DEFINE("DLG2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("ICO1",,oDlg), TBitmap():DEFINE("ICO2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("WAV1",,oDlg), TBitmap():DEFINE("WAV2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("VID1",,oDlg), TBitmap():DEFINE("VID2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("CUR1",,oDlg), TBitmap():DEFINE("CUR2",,oDlg))
   oImageList:Add(TBitmap():DEFINE("CUS1",,oDlg), TBitmap():DEFINE("CUS2",,oDlg))
   
   oTree:= TTreeView():REDEFINE(100, oDlg, 0, , .F. ,"" )
   
   REDEFINE GET       oTxt                                  ID 300 OF oDlg UPDATE
   REDEFINE GET       oGet   VAR cOrigen                    ID 301 OF oDlg UPDATE
   REDEFINE BUTTONBMP oBtn1  TEXTRIGHT RESOURCE "ABRIR"     ID 400 OF oDlg ACTION AnalizaRC(AbrirRC(.F.,cFile))
   REDEFINE BUTTONBMP oBtn2  TEXTRIGHT RESOURCE "EDITAR"    ID 401 OF oDlg ACTION MSGInfo("Editar")
   REDEFINE BUTTONBMP oBtn3  TEXTRIGHT RESOURCE "GUARDAR"   ID 402 OF oDlg ACTION MSGInfo(cSave)//IF( cFileName != Nil .AND. FILE( cFileName ), MEMOWRIT( cFileName, oEditor:GetText() ),), oBtnSave:Disable()
   REDEFINE BUTTONBMP oBtn4  TEXTRIGHT RESOURCE "SALIR"     ID 403 OF oDlg ACTION oImageList:END(), oDlg:END()
    
    oDlg:lHelpIcon:= .F.
    oDlg:bInit:= {|| AnalizaRC(AbrirRC(.T.,cFile))}
   oBtn1:oCursor:= oCur
   oBtn2:oCursor:= oCur
   oBtn3:oCursor:= oCur
   oBtn4:oCursor:= oCur
    
   ACTIVATE DIALOG oDlg CENTERED
  
RETURN Nil


//----------------------------------------------------------------------------//
STATIC FUNCTION AbrirRC(lAuto,cFile)

IF EMPTY(cFile) .AND. lAuto == .F.
   cFile:= cGetFile("Archivo de Recursos en texto     (*.rc)|*.rc|", "Agregar Archivo Recurso", 1,)
ENDIF

IF !EMPTY(cFile)
IF LEN(ALLTRIM(cFileNoPath(cFile))) > 3 .AND. cFileExt(cFile) == "rc"

IF lOpen == .T.
    CierraRC()
ENDIF

   cSave:= cFile
   lOpen:= .T.
   oFile:VarPut(cFile)
   oFile:Refresh()
   RETURN ALLTRIM(cFile)
   
ENDIF
ENDIF

RETURN Nil


//----------------------------------------------------------------------------//
STATIC FUNCTION AnalizaRC(cRCFile)

LOCAL oTxtFile
LOCAL oBmpItem, oDlgItem, oIcoItem, oWavItem, oVidItem, oCurItem, oCusItem
LOCAL aBmpItem,           aIcoItem, aWavItem, aVidItem, aCurItem, aCusItem

IF !EMPTY(cRCFile)
  
  oTree:SetImageList( oImageList )
  oTree:Add( cFileNoExt(cRCFile) )
  oTree:bChanged := {|| Nivel() }

  oTxtFile = TTxtFile():New(cRCFile)
  aBmpItem:= {}
  aIcoItem:= {}
  aWavItem:= {}
  aVidItem:= {}
  aCurItem:= {}
  aCusItem:= {}

   
      WHILE oTxtFile:SKIP()
         
         IF UPPER( StrToken( oTxtFile:cLine, 2 ) ) == "BITMAP"
            AADD(aBmpItem,ALLTRIM(StrToken(oTxtFile:cLine, 3)))
            IF oBmpItem == Nil
               oBmpItem = oTree:Add("MAPA DE BITS",1)
               oBmpItem:Add( StrToken( oTxtFile:cLine, 1 ), 10, {|| oGet:VarPut(aBmpItem[Nivel()]), oGet:Refresh() })
            ELSE
               oBmpItem:Add( StrToken( oTxtFile:cLine, 1 ), 10, {|| oGet:VarPut(aBmpItem[Nivel()]), oGet:Refresh() })
            ENDIF
         ENDIF

         IF UPPER( StrToken( oTxtFile:cLine, 2 ) ) == "DIALOG"
            IF oDlgItem == Nil
               oDlgItem = oTree:Add("DIALOGOS",2)
               oDlgItem:Add( StrToken( oTxtFile:cLine, 1 ), 11, {|| oGet:VarPut("Construir Dialogo"), oGet:Refresh() })
            ELSE
               oDlgItem:Add( StrToken( oTxtFile:cLine, 1 ), 11, {|| oGet:VarPut("con Bwcc32.dll"), oGet:Refresh() })
            ENDIF
         ENDIF

         IF UPPER( StrToken( oTxtFile:cLine, 2 ) ) == "ICON"
            AADD(aIcoItem,ALLTRIM(StrToken(oTxtFile:cLine, 3)))
            IF oIcoItem == Nil
               oIcoItem = oTree:Add("ICONOS",3)
               oIcoItem:Add( StrToken( oTxtFile:cLine, 1 ), 12, {|| oGet:VarPut(aIcoItem[Nivel()]), oGet:Refresh() })
            ELSE
               oIcoItem:Add( StrToken( oTxtFile:cLine, 1 ), 12, {|| oGet:VarPut(aIcoItem[Nivel()]), oGet:Refresh() })
            ENDIF
         ENDIF
         
         IF UPPER( StrToken( oTxtFile:cLine, 2 ) ) == "WAVE"
            AADD(aWavItem,ALLTRIM(StrToken(oTxtFile:cLine, 3)))
            IF oWavItem == Nil
               oWavItem = oTree:Add("SONIDOS",4)
               oWavItem:Add( StrToken( oTxtFile:cLine, 1 ), 13, {|| oGet:VarPut(aWavItem[Nivel()]), oGet:Refresh() })
            ELSE
               oWavItem:Add( StrToken( oTxtFile:cLine, 1 ), 13, {|| oGet:VarPut(aWavItem[Nivel()]), oGet:Refresh() })
            ENDIF
         ENDIF
        
         IF UPPER( StrToken( oTxtFile:cLine, 2 ) ) == "AVI"
            AADD(aVidItem,ALLTRIM(StrToken(oTxtFile:cLine, 3)))
            IF oVidItem == Nil
               oVidItem = oTree:Add("VIDEOS",5)
               oVidItem:Add( StrToken( oTxtFile:cLine, 1 ), 14, {|| oGet:VarPut(aVidItem[Nivel()]), oGet:Refresh() })
            ELSE
               oVidItem:Add( StrToken( oTxtFile:cLine, 1 ), 14, {|| oGet:VarPut(aVidItem[Nivel()]), oGet:Refresh() })
            ENDIF
         ENDIF
         
         IF UPPER( StrToken( oTxtFile:cLine, 2 ) ) == "CURSOR"
            AADD(aCurItem,ALLTRIM(StrToken(oTxtFile:cLine, 3)))
            IF oCurItem == Nil
               oCurItem = oTree:Add("CURSORES",6)
               oCurItem:Add( StrToken( oTxtFile:cLine, 1 ), 15, {|| oGet:VarPut(aCurItem[Nivel()]), oGet:Refresh() })
            ELSE
               oCurItem:Add( StrToken( oTxtFile:cLine, 1 ), 15, {|| oGet:VarPut(aCurItem[Nivel()]), oGet:Refresh() })
            ENDIF
         ENDIF
         
         IF UPPER( StrToken( oTxtFile:cLine, 2 ) ) == "CUSTOM"
            AADD(aCusItem,ALLTRIM(StrToken(oTxtFile:cLine, 3)))
            IF oCusItem == Nil
               oCusItem = oTree:Add("PERSONALIZADO",7)
               oCusItem:Add( StrToken( oTxtFile:cLine, 1 ), 16, {|| oGet:VarPut(aCusItem[Nivel()]), oGet:Refresh() })
            ELSE
               oCusItem:Add( StrToken( oTxtFile:cLine, 1 ), 16, {|| oGet:VarPut(aCusItem[Nivel()]), oGet:Refresh() })
            ENDIF
         ENDIF
          
      END
          
      oTree:nDlgCode:= DLGC_WANTALLKEYS
      oTree:bChanged := {|oTree,oItem| oItem:= oTree:GetSelected(),  IF( oItem # nil .and. ValType( oItem:cargo ) == "B", Eval( oItem:cargo ), nil ) }      
      oTxtFile:END()
             
ENDIF

RETURN Nil


//----------------------------------------------------------------------------//
STATIC FUNCTION CierraRC()

oTree:DeleteAll()
oTree:Cargo = Nil
oTree:Refresh()

RETURN Nil

//----------------------------------------------------------------------------//
STATIC FUNCTION Nivel()

LOCAL nSel
LOCAL oItem:= oTree:GetSelected()
   /*MSGInfo( "Item Numero: " + STR( oItem:ItemLevel() ) + CRLF + ;
            "Prompt: " + oItem:cPrompt + CRLF + ;
            "Posicion: " + STR( SearchItemAt( oItem:cPrompt, .F., oItem ) ) + CRLF + ;
            "Encontrado: " + IF( SearchItemAt( oItem:cPrompt, .T., oItem )," SI", " NO" ) )*/

nSel:= SearchItemAt( oItem:cPrompt, .F., oItem ) 
     
RETURN nSel

//----------------------------------------------------------------------------//
STATIC FUNCTION SearchItemAt( cItem, lItem, oTr )

   LOCAL nPos    := 0
   LOCAL lSw     := .F.
   DEFAULT lItem := .F.

   IF !EMPTY( oTr )
      nPos  := ASCAN( oTr:oParent:aItems, { | o | UPPER( cItem ) $ UPPER( o:cPrompt ) } )
      IF nPos > 0
         lSw:= .T.
      ENDIF   
   ENDIF

RETURN IF( lItem, lSw, nPos )


Gracias de nuevo..
Soluciones y Diseño de Software
Damos Soluciones...

I.S.C. Victor Daniel Cuatecatl Leon
Director y Diseñador de Proyectos

http://www.soldisoft.unlugar.com
http://www.sisa.unlugar.com
danyleon82@hotmail.com
www.facebook.com/victordaniel.cuatecatlleon
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Sub Niveles en Treeview ( SOLUCIONADO )
Posted: Tue Nov 03, 2015 07:39 PM

Ok, me alegro
Gracias

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces

Continue the discussion