How can I detect the Enter key in TTreview Class.

Horizon
Posts: 1325
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

How can I detect the Enter key in TTreview Class.

Post by Horizon »

Hi,

as subject.

Thanks,

Code: Select all | Expand

#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: 1325
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

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

Post by Horizon »

any comments?
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

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

Post by Daniel Garcia-Gil »

Horizon

Code: Select all | Expand

   oTree:nDlgCode = DLGC_WANTALLKEYS
 
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
Horizon
Posts: 1325
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

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

Post by Horizon »

Thank you Daniel,

It works now.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
Posts: 1325
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

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

Post by Horizon »

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
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

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

Post by Daniel Garcia-Gil »

Hakan

this modifies is required in CLASS TTVItem

Add

Code: Select all | Expand



#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


#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
 
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

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

Post by Daniel Garcia-Gil »

Hakan

the changes suggested in last post is already include to next fivewin version (10.11)
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
Horizon
Posts: 1325
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

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

Post by Horizon »

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
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

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

Post by Daniel Garcia-Gil »

Hakan

this modifies is required in CLASS TTVItem

1) ADD

Code: Select all | Expand

  DATA   oParent


2) CHANGE

Code: Select all | Expand

METHOD New( hItem, oTree, Cargo, cPrompt, nImage, oParent )


3) ADD inside METHOD New

Code: Select all | Expand

  ::oParent = oParent


4) ADD

Code: Select all | Expand


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


#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
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
Horizon
Posts: 1325
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

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

Post by Horizon »

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
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

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

Post by Daniel Garcia-Gil »

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
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
lailton.webmaster
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

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

Post by lailton.webmaster »

Work fine for me.

Image
Horizon
Posts: 1325
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

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

Post by Horizon »

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: 1325
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

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

Post by Horizon »

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

#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
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

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

Post by Daniel Garcia-Gil »

Hakan

Code: Select all | Expand


#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
 
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
Post Reply