FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How can I detect the Enter key in TTreview Class.
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
How can I detect the Enter key in TTreview Class.
Posted: Mon Nov 29, 2010 12:52 PM
Hi,

as subject.

Thanks,

Code (fw): Select all Collapse
#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.06
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: How can I detect the Enter key in TTreview Class.
Posted: Mon Nov 29, 2010 06:24 PM

any comments?

Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: How can I detect the Enter key in TTreview Class.
Posted: Mon Nov 29, 2010 06:59 PM
Horizon

Code (fw): Select all Collapse
    oTree:nDlgCode = DLGC_WANTALLKEYS
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: How can I detect the Enter key in TTreview Class.
Posted: Mon Nov 29, 2010 08:25 PM

Thank you Daniel,

It works now.

Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: How can I detect the Enter key in TTreview Class.
Posted: Mon Nov 29, 2010 08: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.06
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: How can I detect the Enter key in TTreview Class.
Posted: Tue Nov 30, 2010 12:18 AM
Hakan

this modifies is required in CLASS TTVItem

Add
Code (fw): Select all Collapse
#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 (fw): Select all Collapse
#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
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: How can I detect the Enter key in TTreview Class.
Posted: Tue Nov 30, 2010 12:31 AM

Hakan

the changes suggested in last post is already include to next fivewin version (10.11)

Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: How can I detect the Enter key in TTreview Class.
Posted: Tue Nov 30, 2010 08: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.06
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: How can I detect the Enter key in TTreview Class.
Posted: Tue Nov 30, 2010 10:55 AM
Hakan

this modifies is required in CLASS TTVItem

1) ADD
Code (fw): Select all Collapse
 聽 DATA 聽 oParent


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


3) ADD inside METHOD New
Code (fw): Select all Collapse
 聽 ::oParent = oParent


4) ADD
Code (fw): Select all Collapse
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





Code (fw): Select all Collapse
#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
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: How can I detect the Enter key in TTreview Class.
Posted: Tue Nov 30, 2010 01: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.06
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: How can I detect the Enter key in TTreview Class.
Posted: Tue Nov 30, 2010 08: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
Posts: 603
Joined: Sun May 04, 2008 08:44 PM
Re: How can I detect the Enter key in TTreview Class.
Posted: Tue Nov 30, 2010 10:14 PM
Work fine for me.

Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: How can I detect the Enter key in TTreview Class.
Posted: Wed Dec 01, 2010 07: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.06
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: How can I detect the Enter key in TTreview Class.
Posted: Wed Dec 01, 2010 01: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 (fw): Select all Collapse
#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.06
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: How can I detect the Enter key in TTreview Class.
Posted: Wed Dec 01, 2010 01:31 PM
Hakan
Code (fw): Select all Collapse
#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