How can I detect the Enter key in TTreview Class.

How can I detect the Enter key in TTreview Class.

Postby Horizon » Mon Nov 29, 2010 12:52 pm

Hi,

as subject.

Thanks,

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

function Main()

   local oDlg, oTree

   DEFINE DIALOG oDlg

   @ 0, 0 TREEVIEW oTree OF oDlg SIZE 200, 200  
    
    oTree:bLDblClick := { |nRow, nCol, nKeyFlags, oItem| MsgInfo(oItem:GetSelText())}
   
    oTree:bKeyDown = { | nKey, nFlags | KeyDown(nKey, nFlags, oTree)}

   ACTIVATE DIALOG oDlg CENTERED ON INIT DefineTree( oTree )


return nil

function DefineTree(oTree)

   local oMenu    := array(3), ;
         oSubMenu := array(10)

   oMenu[1]:= oTree:Add( "Principal" )
      oSubMenu[1]:= oMenu[1]:Add( "Imprimir..." )

   oMenu[2]:= oTree:Add( "Proyectos" )
      oSubMenu[6]:= oMenu[2]:Add( "Definir Proyectos" )
      oSubmenu[7]:= oMenu[2]:Add( "Actualización datos" )

   oTree:expand()

return nil

function KeyDown(nKey, nFlags, oItem)

    ? nKey, "I am here"
   
    IF nKey=VK_RETURN
   
        MsgInfo(oItem:GetSelText())
   
    ENDIF
RETURN
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: How can I detect the Enter key in TTreview Class.

Postby Horizon » Mon Nov 29, 2010 6:24 pm

any comments?
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: How can I detect the Enter key in TTreview Class.

Postby Daniel Garcia-Gil » Mon Nov 29, 2010 6:59 pm

Horizon

Code: Select all  Expand view
   oTree:nDlgCode = DLGC_WANTALLKEYS
 
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: How can I detect the Enter key in TTreview Class.

Postby Horizon » Mon Nov 29, 2010 8:25 pm

Thank you Daniel,

It works now.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: How can I detect the Enter key in TTreview Class.

Postby Horizon » Mon Nov 29, 2010 8:42 pm

Daniel,

Is there any way to find out that the TTVitem is expanded or not?

Thanks,
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: How can I detect the Enter key in TTreview Class.

Postby Daniel Garcia-Gil » Tue Nov 30, 2010 12:18 am

Hakan

this modifies is required in CLASS TTVItem

Add
Code: Select all  Expand view


#define TVM_GETITEMSTATE  TV_FIRST + 39
#define TVIS_EXPANDED           0x0020

   METHOD IsExpanded() INLINE nAnd( ::GetState(), TVIS_EXPANDED ) > 0

   METHOD GetState() INLINE SendMessage( ::oTree:hWnd, TVM_GETITEMSTATE, ::hItem, 0 )

 



Code: Select all  Expand view

#include "FiveWin.ch"

function Main()

   local oDlg, oTree

   DEFINE DIALOG oDlg

   @ 0, 0 TREEVIEW oTree OF oDlg SIZE 200, 200  
   
    oTree:bKeyDown = { | nKey, nFlags | KeyDown(nKey, nFlags, oTree)}

    oTree:nDlgCode = DLGC_WANTALLKEYS

   ACTIVATE DIALOG oDlg CENTERED ON INIT DefineTree( oTree )


return nil

function DefineTree(oTree)

   local oMenu    := array(3), ;
         oSubMenu := array(10)

   oMenu[1]    = oTree:Add( "Principal" )
   oSubMenu[1] = oMenu[1]:Add( "Imprimir..." )
   oSubMenu[1]:Add( "Test 1" )
   oSubMenu[1]:Add( "Test 2" )
   oSubMenu[1]:Add( "Test 3" )
   oSubMenu[1]:Add( "Test 4" )
   

   oMenu[2]    = oTree:Add( "Proyectos" )
   oSubMenu[6] = oMenu[2]:Add( "Definir Proyectos" )
   oSubmenu[7] = oMenu[2]:Add( "Actualización datos" )

   oTree:expand()

return nil

function KeyDown(nKey, nFlags, oTree)

   local oItem := oTree:GetSelected()

    IF nKey=VK_RETURN
        MsgInfo(oItem:IsExpanded())
    ENDIF
   
RETURN
 
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: How can I detect the Enter key in TTreview Class.

Postby Daniel Garcia-Gil » Tue Nov 30, 2010 12:31 am

Hakan

the changes suggested in last post is already include to next fivewin version (10.11)
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: How can I detect the Enter key in TTreview Class.

Postby Horizon » Tue Nov 30, 2010 8:17 am

Thank you Daniel,

I will try it soon.

I use cargo properties as a baction in TTVItem. But sometimes I need also one more cargo properties (You can say that you can use cargo with array. I used it. But the code is more complex than I suggest.). If you modify it is it possible to insert a baction block?

Also Can I find out the Level of oItem?

Thanks again.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: How can I detect the Enter key in TTreview Class.

Postby Daniel Garcia-Gil » Tue Nov 30, 2010 10:55 am

Hakan

this modifies is required in CLASS TTVItem

1) ADD
Code: Select all  Expand view
  DATA   oParent


2) CHANGE
Code: Select all  Expand view
METHOD New( hItem, oTree, Cargo, cPrompt, nImage, oParent )


3) ADD inside METHOD New
Code: Select all  Expand view
  ::oParent = oParent


4) ADD
Code: Select all  Expand view

METHOD ItemLevel( nPrevLevel )
...

METHOD ItemLevel( nPrevLevel ) CLASS TTVItem

   DEFAULT nPrevLevel := 0

   if ::oParent != NIL
      ++nPrevLevel
      ::oParent:ItemLevel( @nPrevLevel )
   endif

RETURN nPrevLevel

 


REMARKS: level 0 is root

download sample

Image

Image

Code: Select all  Expand view

#include "FiveWin.ch"

function Main()

   local oDlg, oTree

   DEFINE DIALOG oDlg SIZE 400, 400

   @ 0, 0 TREEVIEW oTree OF oDlg SIZE 400, 400
   
    oTree:bKeyDown = { | nKey, nFlags | KeyDown(nKey, nFlags, oTree)}

    oTree:nDlgCode = DLGC_WANTALLKEYS

   ACTIVATE DIALOG oDlg CENTERED ON INIT DefineTree( oTree )


return nil

function DefineTree(oTree)

   local oMenu    := array(3), ;
         oSubMenu := array(10), otemp

   oMenu[1]    = oTree:Add( "Principal" )
   oSubMenu[1] = oMenu[1]:Add( "Imprimir..." )
   oTemp = oSubMenu[1]:Add( "Test 1" )
   oTemp = oTemp:Add( "Test 1" )
   oTemp = oTemp:Add( "Test 1" )
   oTemp = oTemp:Add( "Test 1" )
   oTemp = oTemp:Add( "Test 1" )
   oTemp = oTemp:Add( "Test 1" )
   oTemp = oTemp:Add( "Test 1" )
   oTemp:Add( "Test 1" )
   oTemp:Add( "Test 1" )
   oTemp:Add( "Test 1" )
   oTemp:Add( "Test 1" )
   oTemp:Add( "Test 1" )
   
   oSubMenu[1]:Add( "Test 2" )
   oSubMenu[1]:Add( "Test 3" )
   oSubMenu[1]:Add( "Test 4" )
   

   oMenu[2]    = oTree:Add( "Proyectos" )
   oSubMenu[6] = oMenu[2]:Add( "Definir Proyectos" )
   oSubmenu[7] = oMenu[2]:Add( "Actualización datos" )

   oTree:expand()

return nil

function KeyDown(nKey, nFlags, oTree)

   local oItem := oTree:GetSelected()

    IF nKey=VK_RETURN
        MsgInfo( "Level: " + Str( oItem:ItemLevel() ) )
    ENDIF
   
RETURN

 


already include to next fivewin version
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: How can I detect the Enter key in TTreview Class.

Postby Horizon » Tue Nov 30, 2010 1:48 pm

Daniel,

Should I change something in TTreview Class. Your example does not show ItemLevel. It show allways 0.

Thanks,



ps. I have added your chhanges to TTVItem. I have added TTVItem class to my example's builder script.

Edit:syntax
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: How can I detect the Enter key in TTreview Class.

Postby Daniel Garcia-Gil » Tue Nov 30, 2010 8:09 pm

Horizon wrote:Daniel,

Should I change something in TTreview Class. Your example does not show ItemLevel. It show allways 0.

Thanks,


to me working fine.... i use with window 7 and win xp prof

maybe other user can test too and show us
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: How can I detect the Enter key in TTreview Class.

Postby lailton.webmaster » Tue Nov 30, 2010 10:14 pm

Work fine for me.

Image
lailton.webmaster
 
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: How can I detect the Enter key in TTreview Class.

Postby Horizon » Wed Dec 01, 2010 7:49 am

Hi Daniel,

I have downloaded your sample. Exe file works ok.

I have compiled test.prg with xharbour builder. I have added to xhb.obj (because that gives an error about activex.obj) and TTVItem class (that is changed as you described). There is no change.

Could you please send TTVItem class as an e-mail?

Thanks,
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: How can I detect the Enter key in TTreview Class.

Postby Horizon » Wed Dec 01, 2010 1:01 pm

Daniel,

Compile and run sample.
Select Imprimir.
Right click on "Definir Proyectos"

In ShowPopup function, I want to say "Definir Proyectos". The parameter oItem is TTreeview class handle not TTVItem.

Thanks,

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

function Main()

   local oDlg, oTree

   DEFINE DIALOG oDlg SIZE 400, 400

   @ 0, 0 TREEVIEW oTree OF oDlg SIZE 400, 400
   
    oTree:bKeyDown = { | nKey, nFlags | KeyDown(nKey, nFlags, oTree)}
       
        oTree:bRClicked := { | nRow, nCol, nKeyFlags, oItem | ShowPopup( nRow, nCol, nKeyFlags, oItem )}

    oTree:nDlgCode = DLGC_WANTALLKEYS
       
        oTree:Expand()
       
   ACTIVATE DIALOG oDlg CENTERED ON INIT DefineTree( oTree )


return nil

function DefineTree(oTree)

   local oMenu    := array(3), ;
         oSubMenu := array(10), otemp

   oMenu[1]    = oTree:Add( "Principal" )
   oSubMenu[1] = oMenu[1]:Add( "Imprimir..." )
   oTemp = oSubMenu[1]:Add( "Test 1" )
   oTemp = oTemp:Add( "Test 1" )
   oTemp = oTemp:Add( "Test 1" )
   oTemp = oTemp:Add( "Test 1" )
   oTemp = oTemp:Add( "Test 1" )
   oTemp = oTemp:Add( "Test 1" )
   oTemp = oTemp:Add( "Test 1" )
   oTemp:Add( "Test 1" )
   oTemp:Add( "Test 1" )
   oTemp:Add( "Test 1" )
   oTemp:Add( "Test 1" )
   oTemp:Add( "Test 1" )
   
   oSubMenu[1]:Add( "Test 2" )
   oSubMenu[1]:Add( "Test 3" )
   oSubMenu[1]:Add( "Test 4" )
   

   oMenu[2]    = oTree:Add( "Proyectos" )
   oSubMenu[6] = oMenu[2]:Add( "Definir Proyectos" )
   oSubmenu[7] = oMenu[2]:Add( "Actualización datos" )

   oTree:expand()

return nil

function KeyDown(nKey, nFlags, oTree)

   local oItem := oTree:GetSelected()

    IF nKey=VK_RETURN
        MsgInfo( "Level: " + Str( oItem:ItemLevel() ) )
    ENDIF
   
RETURN

function ShowPopup( nRow, nCol, nKeyFlags, oItem )
   
    ? oItem:ClassName(), nKeyFlags
   
    // oItem is a TTreeview not TTVItem.
   
    // How Can I say Test4:cCaption ?


return
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: How can I detect the Enter key in TTreview Class.

Postby Daniel Garcia-Gil » Wed Dec 01, 2010 1:31 pm

Hakan
Code: Select all  Expand view

#include "FiveWin.ch"

function Main()

   local oDlg, oTree

   DEFINE DIALOG oDlg SIZE 400, 400

   @ 0, 0 TREEVIEW oTree OF oDlg SIZE 400, 400
   
    oTree:bKeyDown = { | nKey, nFlags | KeyDown(nKey, nFlags, oTree)}
       
    oTree:bRClicked := { | nRow, nCol, nKeyFlags, oTree | ShowPopup( nRow, nCol, nKeyFlags, oTree )}

    oTree:nDlgCode = DLGC_WANTALLKEYS
       
    oTree:Expand()
       
   ACTIVATE DIALOG oDlg CENTERED ON INIT DefineTree( oTree )


return nil

function DefineTree( oTree )

   local oMenu    := array(3), ;
         oSubMenu := array(10), otemp

   oMenu[1]    = oTree:Add( "Principal" )
   oSubMenu[1] = oMenu[1]:Add( "Imprimir..." )
   oTemp = oSubMenu[1]:Add( "Test 1" )
   oTemp = oTemp:Add( "Test 1" )
   oTemp = oTemp:Add( "Test 1" )
   oTemp = oTemp:Add( "Test 1" )
   oTemp = oTemp:Add( "Test 1" )
   oTemp = oTemp:Add( "Test 1" )
   oTemp = oTemp:Add( "Test 1" )
   oTemp:Add( "Test 1" )
   oTemp:Add( "Test 1" )
   oTemp:Add( "Test 1" )
   oTemp:Add( "Test 1" )
   oTemp:Add( "Test 1" )
   
   oSubMenu[1]:Add( "Test 2" )
   oSubMenu[1]:Add( "Test 3" )
   oSubMenu[1]:Add( "Test 4" )
   

   oMenu[2]    = oTree:Add( "Proyectos" )
   oSubMenu[6] = oMenu[2]:Add( "Definir Proyectos" )
   oSubmenu[7] = oMenu[2]:Add( "Actualización datos" )

   oTree:expand()

return nil

function KeyDown(nKey, nFlags, oTree)

   local oItem := oTree:GetSelected()

    IF nKey=VK_RETURN
        MsgInfo( "Level: " + Str( oItem:ItemLevel() ) )
    ENDIF
   
RETURN

function ShowPopup( nRow, nCol, nKeyFlags, oTree )
   
    local oItem
   
    oItem = oTree:HitTest( nRow, nCol )
    if ! oItem:IsSelected()
       oTree:Select( oItem )
       ? oItem:cPrompt
    endif

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

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 83 guests