Code: Select all | Expand
// Win32 TreeView support
#include "FiveWin.ch"
#include "Constant.ch"
#define TV_FIRST 4352 //0x1100
#define TVM_GETEDITCONTROL ( TV_FIRST + 15 )
#define TVM_EDITLABELA ( TV_FIRST + 14 )
#define TVM_EDITLABELW ( TV_FIRST + 65 )
#ifdef UNICODE
#define TVN_BEGINLABELEDITW ( TVN_FIRST - 59 )
#define TVN_ENDLABELEDITW ( TVN_FIRST - 60 )
#define TVM_EDITLABEL TVM_EDITLABELW
#define TVN_BEGINLABELEDIT TVN_BEGINLABELEDITW
#define TVN_ENDLABELEDIT TVN_ENDLABELEDITW
#else
#define TVN_BEGINLABELEDITA ( TVN_FIRST - 10 )
#define TVN_ENDLABELEDITA ( TVN_FIRST - 11 )
#define TVM_EDITLABEL TVM_EDITLABELA
#define TVN_BEGINLABELEDIT TVN_BEGINLABELEDITA
#define TVN_ENDLABELEDIT TVN_ENDLABELEDITA
#endif
#define TVN_FIRST -400
#define TVN_ITEMEXPANDED (TVN_FIRST-6)
#define COLOR_WINDOW 5
#define COLOR_WINDOWTEXT 8
#define COLOR_BTNFACE 15
#define COLOR_BTNSHADOW 16
#define COLOR_BTNHIGHLIGHT 20
#define FD_BORDER 8
#define FD_HEIGHT 22
#define DT_CENTER 1
#define DT_VCENTER 4
#define WINDING 2
#define SC_KEYMENU 61696 // 0xF100
#define TVS_HASBUTTONS 1
#define TVS_HASLINES 2
#define TVS_LINESATROOT 4
#define TVS_SHOWSELALWAYS 32 // 0x0020
#define TVS_DISABLEDRAGDROP 16 // 0x0010
#define TVS_CHECKBOXES 256 // 0x0100
#define TVS_EDITLABELS 8
#define CTRL_NAME "SysTreeView32"
//----------------------------------------------------------------------------//
CLASS TTreeView FROM TControl
DATA aItems
DATA oImageList
DATA bChanged
DATA bExpanded
DATA hEdit
CLASSDATA aProperties ;
INIT { "aItems", "cTitle", "cVarName", "l3D", "nClrText",;
"nClrPane", "nAlign", "nTop", "nLeft",;
"nWidth", "nHeight", "oFont", "Cargo" }
METHOD New( nTop, nLeft, oWnd, nClrFore,;
nClrBack, lPixel, lDesign, nWidth, nHeight,;
cMsg, lCheckBoxes, bChange, lEditable ) CONSTRUCTOR
METHOD ReDefine( nId, oWnd, nClrFore, nClrBack, lDesign, cMsg ) CONSTRUCTOR
METHOD Add( cPrompt, nImage, nValue )
METHOD VScroll( nWParam, nLParam ) VIRTUAL // standard behavior requested
METHOD HScroll( nWParam, nLParam ) VIRTUAL
METHOD CollapseAll( oItem ) INLINE ScanItems( ::aItems, .f. ),;
oItem := ::GetSelected(), if( oItem <> nil, oItem:MakeVisible(), nil )
METHOD CollapseBranch( oItem ) INLINE ;
If( oItem == nil, oItem := ::GetSelected(),), ;
If( oItem != nil, ( oItem:Collapse(), ScanItems( oItem:aItems, .f. ), oItem:MakeVisible() ),)
METHOD EditLabel( oItem ) INLINE ;
If( oItem == nil, oItem := ::GetSelected(),), ;
If( oItem != nil, oItem:Edit(),)
METHOD Expand() INLINE AEval( ::aItems, { | oItem | oItem:Expand() } )
METHOD ExpandAll( oItem ) INLINE ScanItems( ::aItems, .t. ),;
oItem := ::GetSelected(), if( oItem <> nil, oItem:MakeVisible(), nil )
METHOD ExpandBranch( oItem ) INLINE ;
If( oItem == nil, oItem := ::GetSelected(), nil ), ;
If( oItem != nil, ( oItem:Expand(), ScanItems( oItem:aItems, .t. ), oItem:MakeVisible() ), nil )
METHOD GetEditControl() INLINE TVGetEditControl( ::hWnd )
METHOD GetSelected()
METHOD GetItem( hItem )
METHOD GetItemPos( oItem )
METHOD InsertAfter( oItemParent, cPrompt, nImage, nValue )
METHOD Select( oItem ) INLINE TVSelect( ::hWnd, oItem:hItem )
METHOD GetSelText() INLINE TVGetSelText( ::hWnd )
METHOD GoNext()
METHOD GoPrev()
METHOD GoTop() INLINE If( Len( ::aItems ) > 0, ::Select( ::aItems[ 1 ] ),)
METHOD GoBottom()
METHOD SelChanged() INLINE If( ::bChanged != nil, Eval( ::bChanged, Self ), nil )
METHOD SetImageList( oImageList )
METHOD DeleteAll() INLINE ( TVDelAllItems( ::hWnd ), ::aItems := {} )
METHOD HitTest( nRow, nCol )
METHOD HandleEvent( nMsg, nWParam, nLParam )
METHOD Initiate( hDlg ) INLINE ::Super:Initiate( hDlg ), ::SetColor( ::nClrText, ::nClrPane )
METHOD cToChar() INLINE ::Super:cToChar( CTRL_NAME )
METHOD SetColor( nClrText, nClrPane ) INLINE ;
::Super:SetColor( nClrText, nClrPane ), TVSetColor( ::hWnd, nClrText, nClrPane )
METHOD SwapUp()
METHOD SwapDown()
METHOD Toggle() INLINE AEval( ::aItems, { | oItem | oItem:Toggle() } )
METHOD ToggleAll( oItem ) INLINE ScanItems( ::aItems, , .t. ), ;
oItem := ::GetSelected(), If( oItem <> nil, oItem:MakeVisible(), nil )
METHOD ToggleBranch( oItem ) INLINE ;
If( oItem == nil, oItem := ::GetSelected(), nil ), ;
If( oItem != nil, ( oItem:Toggle(), ScanItems( oItem:aItems, , .t. ), oItem:MakeVisible() ), nil )
METHOD GetCheck( oItem ) INLINE ;
If( oItem == nil, oItem := ::GetSelected(), nil ), ;
TVGetCheck( ::hWnd, oItem:hItem )
METHOD SetCheck( oItem, lOnOff ) INLINE ;
If( oItem == nil, oItem := ::GetSelected(), nil ), ;
TVSetCheck( ::hWnd, oItem:hItem, lOnOff )
METHOD SetItems( aItems )
METHOD GenMenu( lPopup )
METHOD LoadFromMenu( oMenu )
METHOD Notify( nIdCtrl, nPtrNMHDR )
METHOD Scan( bAction )
METHOD SetItemImage( oItem, nImage ) INLINE ;
If( oItem == nil, oItem := ::GetSelected(), nil ), ;
TVSetItemImage( ::hWnd, oItem:hItem, nImage )
METHOD SetItemHeight( nHeight ) INLINE TvSetItemHeight( ::hWnd, nHeight )
METHOD SetSelText( cText ) INLINE ::GetSelected():SetText( cText )
METHOD Len() INLINE Len( ::aItems )
METHOD Count()
ENDCLASS
//----------------------------------------------------------------------------//
METHOD LoadFromMenu( oMenu ) CLASS TTreeView
local n
::DeleteAll()
for n = 1 to Len( oMenu:aItems )
::Add( oMenu:aItems[ n ]:cPrompt )
if ValType( oMenu:aItems[ n ]:bAction ) == "O"
AddSubItems( ATail( ::aItems ), oMenu:aItems[ n ]:bAction )
endif
next
return nil
//----------------------------------------------------------------------------//
static function AddSubItems( oItem, oSubMenu )
local n
for n = 1 to Len( oSubMenu:aItems )
oItem:Add( oSubMenu:aItems[ n ]:cPrompt )
if ValType( oSubMenu:aItems[ n ]:bAction ) == "O"
AddSubItems( ATail( oItem:aItems ), oSubMenu:aItems[ n ]:bAction )
endif
next
return nil
//----------------------------------------------------------------------------//
METHOD New( nTop, nLeft, oWnd, nClrFore,;
nClrBack, lPixel, lDesign, nWidth, nHeight, cMsg, lCheckBoxes, bChange, lEditable ) CLASS TTreeView
DEFAULT nTop := 0, nLeft := 0,;
oWnd := GetWndDefault(),;
nClrFore := oWnd:nClrText,;
nClrBack := GetSysColor( COLOR_WINDOW ),;
lPixel := .f.,;
lDesign := .f.,;
nWidth := 150,;
nHeight := 150,;
lCheckBoxes := .F.,;
lEditable := .F.
::lUnicode = FW_SetUnicode()
::nStyle = nOR( WS_CHILD, WS_VISIBLE, CS_VREDRAW, CS_HREDRAW,;
If( lDesign, WS_CLIPSIBLINGS, 0 ), WS_TABSTOP,;
TVS_HASBUTTONS, TVS_HASLINES, TVS_LINESATROOT, TVS_SHOWSELALWAYS, TVS_DISABLEDRAGDROP,;
If( lCheckBoxes, TVS_CHECKBOXES, 0 ),;
If( lEditable, TVS_EDITLABELS, 0 ) )
::nId = ::GetNewId()
::oWnd = oWnd
::cMsg = cMsg
::nTop = If( lPixel, nTop, nTop * SAY_CHARPIX_H )
::nLeft = If( lPixel, nLeft, nLeft * SAY_CHARPIX_W )
::nBottom = ::nTop + nHeight - 1
::nRight = ::nLeft + nWidth - 1
::lDrag = lDesign
::lCaptured = .f.
::nClrText = nClrFore
::nClrPane = nClrBack
::aItems = {}
::bChanged = bChange
if ! Empty( oWnd:hWnd )
::Create( CTRL_NAME )
oWnd:AddControl( Self )
::SetColor( nClrFore, nClrBack )
else
oWnd:DefControl( Self )
endif
::Default()
::lDrag = lDesign
if lDesign
::CheckDots()
endif
return Self
//----------------------------------------------------------------------------//
METHOD ReDefine( nId, oWnd, nClrFore, nClrBack, lDesign, cMsg, bChange ) CLASS TTreeView
DEFAULT oWnd := GetWndDefault(),;
nClrFore := oWnd:nClrText,;
nClrBack := oWnd:nClrPane,; // GetSysColor( COLOR_WINDOW ),;
lDesign := .f.
::lUnicode = FW_SetUnicode()
::nId = nId
::oWnd = oWnd
::aItems = {}
::nClrText = nClrFore
::nClrPane = nClrBack
::bChanged = bChange
::Register( nOR( CS_VREDRAW, CS_HREDRAW, TVS_HASBUTTONS, TVS_HASLINES, TVS_LINESATROOT ) )
oWnd:DefControl( Self )
return Self
//----------------------------------------------------------------------------//
METHOD Add( cPrompt, nImage, nValue ) CLASS TTreeView
local oItem
oItem := TTVItem():New( TVInsertItem( ::hWnd, cPrompt,, nImage, nValue ), Self )
oItem:cPrompt := cPrompt
oItem:nImage := nImage
AAdd( ::aItems, oItem )
return oItem
//----------------------------------------------------------------------------//
METHOD Count() CLASS TTreeView
local nItems := 0, bAction := { | oItem | nItems++, .F. }
::Scan( bAction )
return nItems
//----------------------------------------------------------------------------//
METHOD InsertAfter( oItem, cPrompt, nImage, nValue ) CLASS TTreeView
local oNewItem, nAt, oLastItem
oNewItem := TTVItem():New( TVInsertItem( ::hWnd, cPrompt, oItem:oParent:hItem, nImage, nValue, oItem:hItem ), Self )
oNewItem:cPrompt := cPrompt
oNewItem:nImage := nImage
oNewItem:oParent := oItem:oParent
if ( nAt := AScan( oItem:oParent:aItems, { | oIt | oItem:hItem == oIt:hItem } ) ) != 0
oLastItem = ATail( oItem:oParent:aItems )
AIns( oItem:oParent:aItems, nAt + 1 )
AAdd( oItem:oParent:aItems, oLastItem )
oItem:oParent:aItems[ nAt + 1 ] = oNewItem
// XBrowse( oItem:oParent:aItems )
endif
return oNewItem
//----------------------------------------------------------------------------//
static function ScanItems( aItems, lExpand, lToggle )
local oItem, i
DEFAULT lExpand := .t., lToggle := .f.
for i := 1 to Len( aItems )
oItem = aItems[ i ]
if lToggle
oItem:Toggle()
elseif lExpand
oItem:Expand()
else
oItem:Collapse()
endif
if Len( oItem:aItems ) != 0
ScanItems( oItem:aItems, lExpand, lToggle )
endif
next
return nil
//----------------------------------------------------------------------------//
static function ScanItemsBlock( aItems, bAction )
local oItem, n := 1, oItemFound
while n <= Len( aItems ) .and. oItemFound == nil
oItem = aItems[ n ]
if Eval( bAction, oItem, n )
return oItem
else
if Len( oItem:aItems ) > 0
oItemFound = ScanItemsBlock( oItem:aItems, bAction )
endif
endif
n++
end
return oItemFound
//----------------------------------------------------------------------------//
METHOD GenMenu( lPopup ) CLASS TTreeView
local oMenu
DEFAULT lPopup := .T.
if Len( ::aItems ) > 0
if lPopup
MENU oMenu POPUP
else
MENU oMenu
endif
GenMenuItems( ::aItems )
ENDMENU
endif
return oMenu
//----------------------------------------------------------------------------//
static function GenMenuItems( aItems )
local n
for n = 1 to Len( aItems )
MENUITEM aItems[ n ]:GetText()
if Len( aItems[ n ]:aItems ) > 0
MENU
GenMenuItems( aItems[ n ]:aItems )
ENDMENU
endif
next
return nil
//----------------------------------------------------------------------------//
METHOD GetSelected() CLASS TTreeView
return SearchItem( ::aItems, TVGetSelected( ::hWnd ) )
//----------------------------------------------------------------------------//
METHOD GetItem( hItem ) CLASS TTreeView
return SearchItem( ::aItems, hItem )
//----------------------------------------------------------------------------//
METHOD GetItemPos( oItem ) CLASS TTreeView
return AScan( ::aItems, { | o | o == oItem } )
//----------------------------------------------------------------------------//
METHOD GoBottom() CLASS TTreeView
local oLastItem
::Scan( { | oItem | oLastItem := oItem, .F. } )
::Select( oLastItem )
return nil
//----------------------------------------------------------------------------//
METHOD GoPrev() CLASS TTreeView
local oSelItem, oPrevItem
if ( oSelItem := ::GetSelected() ) != nil
::Scan( { | oItem | If( oItem:hItem != oSelItem:hItem, oPrevItem := oItem,),;
oItem:hItem == oSelItem:hItem } )
if oPrevItem != nil
::Select( oPrevItem )
else
::GoBottom()
endif
endif
return nil
//----------------------------------------------------------------------------//
METHOD GoNext() CLASS TTreeView
local oSelItem := ::GetSelected(), lStop := .F., oNextItem
::Scan( { | oItem | If( oItem:hItem == oSelItem:hItem, lStop := .T.,),;
If( lStop .and. oItem:hItem != oSelItem:hItem, ( oNextItem := oItem, .T. ), .F. ) } )
if oNextItem != nil
::Select( oNextItem )
else
::GoTop()
endif
return nil
//----------------------------------------------------------------------------//
METHOD HitTest( nRow, nCol ) CLASS TTreeView
local hItem
hItem := TVHitTest( ::hWnd, nRow, nCol )
If hItem > 0
return ::GetItem( hItem )
Endif
return nil
//----------------------------------------------------------------------------//
METHOD Notify( nIdCtrl, nPtrNMHDR ) CLASS TTreeView
local nCode := GetNMHDRCode( nPtrNMHDR )
do case
case nCode == TVN_ITEMEXPANDED
if ! Empty( ::bExpanded )
if NMTREEVIEWAction( nPtrNMHDR ) == 2 // Expanded
Eval( ::bExpanded, NMTREEVIEWItemNew( nPtrNMHDR ) ) // hItem
endif
endif
case nCode == TVN_BEGINLABELEDIT
::hEdit := SendMessage( ::hWnd, TVM_GETEDITCONTROL, 0, 0 )
return 0
case nCode == TVN_ENDLABELEDIT
::SetSelText( GetWindowText( ::hEdit ) )
::hEdit := nil
endcase
return nil
//----------------------------------------------------------------------------//
METHOD Scan( bAction ) CLASS TTreeView
return ScanItemsBlock( ::aItems, bAction )
//----------------------------------------------------------------------------//
METHOD SetImageList( oImageList ) CLASS TTreeView
::oImageList = oImageList
TVSetImageList( ::hWnd, oImageList:hImageList, 0 )
return nil
//----------------------------------------------------------------------------//
METHOD SwapDown() CLASS TTreeView
local oSelItem := ::GetSelected(), cPrompt := oSelItem:cPrompt
::GoNext()
oSelItem:End()
::Select( ::InsertAfter( ::GetSelected(), cPrompt ) )
return nil
//----------------------------------------------------------------------------//
METHOD SwapUp() CLASS TTreeView
local oSelItem := ::GetSelected(), cPrompt := oSelItem:cPrompt
::GoPrev()
::GoPrev()
oSelItem:End()
::Select( ::InsertAfter( ::GetSelected(), cPrompt ) )
return nil
//----------------------------------------------------------------------------//
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TTreeView
local oItem
do case
case nMsg == WM_CHAR
if nWParam == VK_RETURN
return 1
endif
endcase
return ::Super:HandleEvent( nMsg, nWParam, nLParam )
//----------------------------------------------------------------------------//
METHOD SetItems( aItems ) CLASS TTreeView
local n
for n = 1 to Len( aItems )
::Add( aItems[ n ] )
next
return nil
//----------------------------------------------------------------------------//
static function SearchItem( aItems, hItem )
local n, oItem
for n = 1 to Len( aItems )
if Len( aItems[ n ]:aItems ) > 0
if ( oItem := SearchItem( aItems[ n ]:aItems, hItem ) ) != nil
return oItem
endif
endif
if aItems[ n ]:hItem == hItem
return aItems[ n ]
endif
next
return nil
//----------------------------------------------------------------------------//
Code: Select all | Expand
// Win95 Class TTreeView items support ( TTVItem --> TreeViewItem )
#include "FiveWin.ch"
#define TV_FIRST 4352 // 0x1100
#define TVM_EXPAND TV_FIRST + 2
#define TVE_COLLAPSE 1
#define TVE_EXPAND 2
#define TVE_TOGGLE 3
#define TVM_ENSUREVISIBLE TV_FIRST + 20
#define TVM_GETITEMSTATE TV_FIRST + 39
//item state
#define TVIS_SELECTED 0x0002
#define TVIS_CUT 0x0004
#define TVIS_DROPHILITED 0x0008
#define TVIS_BOLD 0x0010
#define TVIS_EXPANDED 0x0020
#define TVIS_EXPANDEDONCE 0x0040
//----------------------------------------------------------------------------//
CLASS TTVItem
DATA oParent
DATA hItem
DATA oTree
DATA aItems
DATA cPrompt
DATA nImage
DATA Cargo
DATA lBold INIT .F.
METHOD New( hItem, oTree, Cargo ) CONSTRUCTOR
METHOD Add( cPrompt, nImage, Cargo )
METHOD Bold() INLINE TVSetItemBold( ::oTree:hWnd, ::hItem, .T. )
METHOD Normal() INLINE TVSetItemBold( ::oTree:hWnd, ::hItem, .F. )
METHOD DeleteBranches()
METHOD DelItemPos( nPos )
METHOD Edit() INLINE TVEditLabel( ::oTree:hWnd, ::hItem )
METHOD Expand() INLINE ;
SendMessage( ::oTree:hWnd, TVM_EXPAND, TVE_EXPAND, ::hItem )
METHOD Collapse() INLINE ;
SendMessage( ::oTree:hWnd, TVM_EXPAND, TVE_COLLAPSE, ::hItem )
METHOD GetItemPos( oItem )
METHOD GetParent() INLINE ;
::oTree:GetItem( TVGetParent( ::oTree:hWnd, ::hItem ) )
METHOD IsExpanded() INLINE nAnd( ::GetState(), TVIS_EXPANDED ) > 0
METHOD IsSelected() INLINE nAnd( ::GetState(), TVIS_SELECTED ) > 0
METHOD ItemLevel( nPrevLevel )
METHOD SetText( cText ) INLINE ;
TVSetItemText( ::oTree:hWnd, ::hItem, cText )
METHOD Set( cText, nImage )
METHOD Toggle() INLINE ;
SendMessage( ::oTree:hWnd, TVM_EXPAND, TVE_TOGGLE, ::hItem )
METHOD MakeVisible() INLINE ;
SendMessage( ::oTree:hWnd, TVM_ENSUREVISIBLE, 0, ::hItem )
METHOD SetCheck( lOnOff ) INLINE ::oTree:SetCheck( Self, lOnOff )
METHOD GetCheck() INLINE ::oTree:GetCheck( Self )
METHOD GetState() INLINE SendMessage( ::oTree:hWnd, TVM_GETITEMSTATE, ::hItem, 0 )
METHOD GetText() INLINE TVGetText( ::oTree:hWnd, ::hItem )
METHOD SetText( cText ) INLINE TVSetItemText( ::oTree:hWnd, ::hItem, cText )
ACCESS cPrompt INLINE TVGetText( ::oTree:hWnd, ::hItem )
ASSIGN cPrompt( cText ) INLINE TVSetItemText( ::oTree:hWnd, ::hItem, cText )
METHOD End()
METHOD Len() INLINE Len( ::aItems )
METHOD Count()
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New( hItem, oTree, Cargo, cPrompt, nImage, oParent ) CLASS TTVItem
::aItems = {}
::hItem = hItem
::oTree = oTree
::Cargo = Cargo
::cPrompt = cPrompt
::nImage = nImage
::oParent = oParent
return Self
//----------------------------------------------------------------------------//
METHOD Add( cPrompt, nImage, Cargo ) CLASS TTVItem
local oItem := TTVItem():New( TVInsertItem( ::oTree:hWnd, cPrompt,;
::hItem, nImage ), ::oTree, Cargo, cPrompt, nImage, Self )
AAdd( ::aItems, oItem )
oItem:oParent = Self
return oItem
//----------------------------------------------------------------------------//
METHOD Count() CLASS TTVItem
local oItem, nItems := 1
for each oItem in ::aItems
nItems += 1 + If( ! Empty( oItem:aItems ), ( oItem:Count() - 1 ), 0 )
next
return nItems
//----------------------------------------------------------------------------//
METHOD DeleteBranches() CLASS TTVItem
AEval( ::aItems, { | o | TVDeleteItem( ::oTree:hWnd, o:hItem ) } )
::aItems = {}
return nil
//----------------------------------------------------------------------------//
METHOD DelItemPos( nPos ) CLASS TTVItem
if nPos > 0 .and. nPos <= Len( ::aItems )
TVDeleteItem( ::oTree:hWnd, ::aItems[ nPos ]:hItem )
ADel( ::aItems, nPos )
ASize( ::aItems, Len( ::aItems ) - 1 )
endif
return nil
//----------------------------------------------------------------------------//
METHOD End() CLASS TTVItem
local nAt := 0
if ! Empty( ::oParent )
nAt := AScan( ::oParent:aItems, { | o | o == Self } )
endif
if nAt != 0
if ::oParent:IsKindOf( "TTREEVIEW" )
ADel( ::oTree:aItems, nAt )
ASize( ::oTree:aItems, Len( ::oTree:aItems ) - 1 )
else
ADel( ::oParent:aItems, nAt )
ASize( ::oParent:aItems, Len( ::oParent:aItems ) - 1 )
endif
endif
TVDeleteItem( ::oTree:hWnd, ::hItem )
return nil
//----------------------------------------------------------------------------//
METHOD GetItemPos( oItem ) CLASS TTVItem
return AScan( ::aItems, { | o | o == oItem } )
//----------------------------------------------------------------------------//
METHOD ItemLevel( nPrevLevel ) CLASS TTVItem
DEFAULT nPrevLevel := 0
if ::oParent != NIL
++nPrevLevel
::oParent:ItemLevel( @nPrevLevel )
endif
RETURN nPrevLevel
//----------------------------------------------------------------------------//
METHOD Set( cPrompt, nImage ) CLASS TTVItem
DEFAULT cPrompt := ::cPrompt, nImage := ::nImage
TVSetTextImage( ::oTree:hWnd, ::hItem, cPrompt, nImage )
return nil
//----------------------------------------------------------------------------//
Code: Select all | Expand
// Windows 95 TreeView control support C routines
#define UNICODE
#define _UNICODE
#define NONAMELESSUNION
#define _WIN32_IE 0x0500
#include <Windows.h>
#include <CommCtrl.h>
#include <hbapi.h>
#ifdef _MSC_VER
#define TVM_GETITEMSTATE (TV_FIRST + 39)
#endif
#ifdef __GNUC__
#define TreeView_SetCheckState(hwndTV, hti, fCheck) TreeView_SetItemState(hwndTV, hti, INDEXTOSTATEIMAGEMASK((fCheck)?2:1), TVIS_STATEIMAGEMASK)
#define TreeView_GetCheckState(hwndTV, hti) ((((UINT)(SNDMSG((hwndTV), TVM_GETITEMSTATE, (WPARAM)(hti), TVIS_STATEIMAGEMASK))) >> 12) -1)
#endif
#ifndef _WIN64
#define fw_parH( i ) ( (HANDLE) hb_parnl( i ) )
#define fw_retnll( l ) hb_retnl( (LONG) l )
#else
#define fw_parH( i ) ( (HANDLE) hb_parnll( i ) )
#define fw_retnll( l ) hb_retnll( (LONGLONG) l )
#endif
LPWSTR fw_parWide( int iParam );
LPSTR UTF16toSTR8( LPWSTR utf16, int iLen );
size_t wcslen( const wchar_t* wcs );
//-------------------------------------------------------------------------//
HB_FUNC( TVINSERTITEM ) // ( hWnd, cItemText, hItem, nImage, nValue, hItem )
{
TV_INSERTSTRUCT is;
HTREEITEM hItem;
memset( ( char * ) &is, 0, sizeof( TV_INSERTSTRUCT ) );
#ifndef _WIN64
is.hParent = ( HTREEITEM ) hb_parnl( 3 );
#else
is.hParent = ( HTREEITEM ) hb_parnll( 3 );
#endif
// #if (_WIN32_IE >= 0x0400)
#ifdef __BORLANDC__
#if __BORLANDC__ <= 1410
is.DUMMYUNIONNAME.item.pszText = fw_parWide( 2 ); //hb_parc( 2 );
is.DUMMYUNIONNAME.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
is.DUMMYUNIONNAME.item.iImage = hb_parnl( 4 );
is.DUMMYUNIONNAME.item.iSelectedImage = hb_parnl( 4 );
is.DUMMYUNIONNAME.item.lParam = hb_parnl( 5 );
#else
is.item.pszText = fw_parWide( 2 ); //hb_parc( 2 );
is.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
is.item.iImage = hb_parnl( 4 );
is.item.iSelectedImage = hb_parnl( 4 );
is.item.lParam = hb_parnl( 5 );
#endif
#else
is.u.item.pszText = fw_parWide( 2 ); //hb_parc( 2 );
is.u.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
is.u.item.iImage = hb_parnl( 4 );
is.u.item.iSelectedImage = hb_parnl( 4 );
is.u.item.lParam = hb_parnl( 5 );
#endif
if( ( hb_pcount() > 5 ) && ( hItem = ( HTREEITEM ) hb_parnll( 6 ) ) )
{
is.hInsertAfter = hItem;
}
#ifndef _WIN64
hb_retnl( SendMessage( ( HWND ) hb_parnl( 1 ), TVM_INSERTITEM, 0,
( LPARAM )( LPTV_INSERTSTRUCT )( &is ) ) );
#else
hb_retnll( SendMessage( ( HWND ) hb_parnll( 1 ), TVM_INSERTITEM, 0,
( LPARAM )( LPTV_INSERTSTRUCT )( &is ) ) );
#endif
#ifdef __BORLANDC__
#if __BORLANDC__ <= 1410
hb_xfree( ( void * ) is.DUMMYUNIONNAME.item.pszText );
#else
hb_xfree( ( void * ) is.item.pszText );
#endif
#else
hb_xfree( ( void * ) is.u.item.pszText );
#endif
}
//-------------------------------------------------------------------------//
HB_FUNC( TVSETIMAGELIST ) // ( hWnd, hImageList, nType )
{
#ifndef _WIN64
hb_retnl( ( LONG ) TreeView_SetImageList( ( HWND ) hb_parnl( 1 ),
( HIMAGELIST ) hb_parnl( 2 ), hb_parnl( 3 ) ) );
#else
hb_retnll( ( LONGLONG ) TreeView_SetImageList( ( HWND ) hb_parnll( 1 ),
( HIMAGELIST ) hb_parnll( 2 ), hb_parnl( 3 ) ) );
#endif
}
//-------------------------------------------------------------------------//
HB_FUNC( TVGETSELTEXT ) // ( hWnd ) --> cText
{
#ifndef _WIN64
HWND hWnd = ( HWND ) hb_parnl( 1 );
#else
HWND hWnd = ( HWND ) hb_parnll( 1 );
#endif
HTREEITEM hItem = TreeView_GetSelection( hWnd );
TV_ITEM tvi;
BYTE buffer[ 200 ];
LPSTR szRet;
if( hItem )
{
tvi.mask = TVIF_TEXT;
tvi.hItem = hItem;
tvi.pszText = (LPWSTR) buffer; //( char * ) buffer;
tvi.cchTextMax = 100;
TreeView_GetItem( hWnd, &tvi );
// hb_retc( tvi.pszText );
szRet = UTF16toSTR8( (LPWSTR) buffer, wcslen( (LPWSTR) buffer ) );
hb_retc( szRet );
hb_xfree( ( void * ) szRet );
}
else
hb_retc( "" );
}
//-------------------------------------------------------------------------//
HB_FUNC( TVGETTEXT ) // ( hWnd, hItem ) --> cText
{
#ifndef _WIN64
HTREEITEM hItem = ( HTREEITEM ) hb_parnl( 2 );
#else
HTREEITEM hItem = ( HTREEITEM ) hb_parnll( 2 );
#endif
TV_ITEM tvi;
BYTE buffer[ 200 ];
LPSTR szRet;
tvi.mask = TVIF_TEXT;
tvi.hItem = hItem;
tvi.pszText = (LPWSTR) buffer; //( char * ) buffer;
tvi.cchTextMax = 100;
#ifndef _WIN64
TreeView_GetItem( ( HWND ) hb_parnl( 1 ), &tvi );
#else
TreeView_GetItem( ( HWND ) hb_parnll( 1 ), &tvi );
#endif
// hb_retc( tvi.pszText );
szRet = UTF16toSTR8( (LPWSTR) buffer, wcslen( (LPWSTR) buffer ) );
hb_retc( szRet );
hb_xfree( ( void * ) szRet );
}
//-------------------------------------------------------------------------//
HB_FUNC( TVSETITEMTEXT ) // ( hWnd, hItem, cText )
{
#ifndef _WIN64
HWND hWnd = ( HWND ) hb_parnl( 1 );
#else
HWND hWnd = ( HWND ) hb_parnll( 1 );
#endif
TV_ITEM tvi;
BOOL bResult;
BYTE buffer[ 200 ];
#ifndef _WIN64
tvi.hItem = ( HTREEITEM ) hb_parnl( 2 );
#else
tvi.hItem = ( HTREEITEM ) hb_parnll( 2 );
#endif
tvi.mask = TVIF_TEXT;
tvi.pszText = (LPWSTR) buffer; //( char * ) buffer;
tvi.cchTextMax = 100; //sizeof( buffer );
bResult = TreeView_GetItem( hWnd, &tvi );
if( bResult )
{
tvi.mask = TVIF_TEXT;
#ifndef _WIN64
tvi.hItem = ( HTREEITEM ) hb_parnl( 2 );
#else
tvi.hItem = ( HTREEITEM ) hb_parnll( 2 );
#endif
tvi.pszText = fw_parWide( 3 ); //( LPSTR ) hb_parc( 3 );
tvi.cchTextMax = wcslen( tvi.pszText ); //hb_parclen( 3 );
TreeView_SetItem( hWnd, &tvi );
hb_xfree( ( void * ) tvi.pszText );
}
}
//-------------------------------------------------------------------------//
HB_FUNC( TVGETSELECTED ) // ( hWnd ) --> hItem
{
#ifndef _WIN64
hb_retnl( ( LONG ) TreeView_GetSelection( ( HWND ) hb_parnl( 1 ) ) );
#else
hb_retnll( ( LONGLONG ) TreeView_GetSelection( ( HWND ) hb_parnll( 1 ) ) );
#endif
}
//-------------------------------------------------------------------------//
HB_FUNC( TVDELALLITEMS ) // ( hWnd ) --> lSuccess
{
#ifndef _WIN64
hb_retl( ( BOOL ) TreeView_DeleteAllItems( ( HWND ) hb_parnl( 1 ) ) );
#else
hb_retl( ( BOOL ) TreeView_DeleteAllItems( ( HWND ) hb_parnll( 1 ) ) );
#endif
}
//-------------------------------------------------------------------------//
HB_FUNC( TVHITTEST ) // ( hWnd, nRow, nCol ) --> hItem
{
#ifndef _WIN64
HWND hWnd = ( HWND ) hb_parnl( 1 );
#else
HWND hWnd = ( HWND ) hb_parnll( 1 );
#endif
TV_HITTESTINFO lpht;
HTREEITEM hItem;
lpht.pt.x = hb_parnl( 3 );
lpht.pt.y = hb_parnl( 2 );
hItem = TreeView_HitTest( hWnd, &lpht );
if( ( hItem != NULL ) && ( lpht.flags & TVHT_ONITEM ) )
#ifndef _WIN64
hb_retnl( ( LONG ) hItem );
#else
hb_retnll( ( LONGLONG ) hItem );
#endif
else
hb_retnl( ( LONG ) 0 );
}
//-------------------------------------------------------------------------//
HB_FUNC( TVSELECT ) // ( hWnd, hItem ) --> lSuccess
{
#ifndef _WIN64
HWND hWnd = ( HWND ) hb_parnl( 1 );
HTREEITEM hItem = ( HTREEITEM ) hb_parnl( 2 );
#else
HWND hWnd = ( HWND ) hb_parnll( 1 );
HTREEITEM hItem = ( HTREEITEM ) hb_parnll( 2 );
#endif
hb_retl( ( BOOL ) TreeView_Select( hWnd, hItem, TVGN_CARET ) );
}
//-------------------------------------------------------------------------//
HB_FUNC( TVDELETEITEM ) // ( hWnd, hItem ) --> lSuccess
{
#ifndef _WIN64
HWND hWnd = ( HWND ) hb_parnl( 1 );
HTREEITEM hItem = ( HTREEITEM ) hb_parnl( 2 );
#else
HWND hWnd = ( HWND ) hb_parnll( 1 );
HTREEITEM hItem = ( HTREEITEM ) hb_parnll( 2 );
#endif
hb_retl( TreeView_DeleteItem( hWnd, hItem ) );
}
//-------------------------------------------------------------------------//
HB_FUNC( TVEDITLABEL ) // ( hWnd, hItem ) --> lSuccess
{
#ifndef _WIN64
HWND hWnd = ( HWND ) hb_parnl( 1 );
HTREEITEM hItem = ( HTREEITEM ) hb_parnl( 2 );
#else
HWND hWnd = ( HWND ) hb_parnll( 1 );
HTREEITEM hItem = ( HTREEITEM ) hb_parnll( 2 );
#endif
SetFocus( hWnd );
TreeView_EditLabel( hWnd, hItem );
}
//-------------------------------------------------------------------------//
HB_FUNC( TVGETPARENT ) // ( hWnd, hItem ) --> hParentItem
{
#ifndef _WIN64
HWND hWnd = ( HWND ) hb_parnl( 1 );
HTREEITEM hItem = ( HTREEITEM ) hb_parnl( 2 );
#else
HWND hWnd = ( HWND ) hb_parnll( 1 );
HTREEITEM hItem = ( HTREEITEM ) hb_parnll( 2 );
#endif
#ifndef _WIN64
hb_retnl( ( unsigned long ) TreeView_GetParent( hWnd, hItem ) );
#else
hb_retnll( ( LONGLONG ) TreeView_GetParent( hWnd, hItem ) );
#endif
}
//-------------------------------------------------------------------------//
HB_FUNC( TVSETTEXTIMAGE ) // ( hWnd, hItem, cText, nImage )
{
#ifndef _WIN64
HWND hWnd = ( HWND ) hb_parnl( 1 );
HTREEITEM hItem = ( HTREEITEM ) hb_parnl( 2 );
#else
HWND hWnd = ( HWND ) hb_parnll( 1 );
HTREEITEM hItem = ( HTREEITEM ) hb_parnll( 2 );
#endif
TV_ITEM tvi;
tvi.hItem = hItem;
tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
tvi.pszText = fw_parWide( 3 ); //( LPSTR ) hb_parc( 3 );
tvi.iImage = hb_parnl( 4 );
tvi.iSelectedImage = hb_parnl( 4 );
TreeView_SetItem( hWnd, &tvi );
hb_xfree( ( void * ) tvi.pszText );
}
//-------------------------------------------------------------------------//
HB_FUNC( TVSETCOLOR ) // hWnd, nClrFore, nClrBack
{
#ifndef _WIN64
COLORREF clr = TreeView_SetBkColor( ( HWND ) hb_parnl( 1 ), hb_parnl( 3 ) );
COLORREF clr2 = TreeView_SetTextColor( ( HWND ) hb_parnl( 1 ), hb_parnl( 2 ) );
#else
COLORREF clr = TreeView_SetBkColor( ( HWND ) hb_parnll( 1 ), hb_parnl( 3 ) );
COLORREF clr2 = TreeView_SetTextColor( ( HWND ) hb_parnll( 1 ), hb_parnl( 2 ) );
#endif
HB_SYMBOL_UNUSED( clr );
HB_SYMBOL_UNUSED( clr2 );
}
//-------------------------------------------------------------------------//
HB_FUNC( TVSETCHECK ) // hTreeView, hItem, lOnOff
{
#ifndef _WIN64
TreeView_SetCheckState( ( HWND ) hb_parnl( 1 ),
( HTREEITEM ) hb_parnl( 2 ), hb_parl( 3 ) );
#else
TreeView_SetCheckState( ( HWND ) hb_parnll( 1 ),
( HTREEITEM ) hb_parnll( 2 ), hb_parl( 3 ) );
#endif
}
//-------------------------------------------------------------------------//
HB_FUNC( TVGETCHECK ) // hTreeView, hItem --> lOnOff
{
#ifndef _WIN64
hb_retl( TreeView_GetCheckState( ( HWND ) hb_parnl( 1 ),
( HTREEITEM ) hb_parnl( 2 ) ) );
#else
hb_retl( TreeView_GetCheckState( ( HWND ) hb_parnll( 1 ),
( HTREEITEM ) hb_parnll( 2 ) ) );
#endif
}
//-------------------------------------------------------------------------//
HB_FUNC( TVGETEDITCONTROL ) // hTreeView --> hEdit
{
#ifndef _WIN64
hb_retnl( ( HB_ULONG ) TreeView_GetEditControl( ( HWND ) hb_parnl( 1 ) ) );
#else
hb_retnll( ( HB_LONGLONG ) TreeView_GetEditControl( ( HWND ) hb_parnll( 1 ) ) );
#endif
}
//-------------------------------------------------------------------------//
HB_FUNC( TVIPARAM ) // hItem --> nLParam
{
#ifndef _WIN64
hb_retnl( ( ( TV_ITEM * ) hb_parnl( 1 ) )->lParam );
#else
hb_retnll( ( ( TV_ITEM * ) hb_parnll( 1 ) )->lParam );
#endif
}
//-------------------------------------------------------------------------//
HB_FUNC( TVSETITEMIMAGE ) // ( hWnd, hItem, iImage ) --> lSuccess
{
#ifndef _WIN64
HWND hWnd = ( HWND ) hb_parnl( 1 );
#else
HWND hWnd = ( HWND ) hb_parnll( 1 );
#endif
UINT iImage = hb_parni( 3 ) + 1;
TV_ITEM pitem;
#ifndef _WIN64
pitem.hItem = ( HTREEITEM ) hb_parnl( 2 );
#else
pitem.hItem = ( HTREEITEM ) hb_parnll( 2 );
#endif
pitem.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
pitem.iImage = iImage;
pitem.iSelectedImage = iImage;
hb_retl( TreeView_SetItem( hWnd, ( LPTV_ITEM )( &pitem ) ) );
}
//-------------------------------------------------------------------------//
HB_FUNC( TVSETITEMHEIGHT )// ( hWnd, cyItemn ) --> lSuccess
{
#ifndef _WIN64
hb_retl( TreeView_SetItemHeight( ( HWND ) hb_parnl( 1 ), hb_parni( 2 ) ) );
#else
hb_retl( TreeView_SetItemHeight( ( HWND ) hb_parnll( 1 ), hb_parni( 2 ) ) );
#endif
}
//-------------------------------------------------------------------------//
HB_FUNC( TVSETITEMBOLD ) // ( hWnd, hTreeItem, lBold ) --> lSuccess
{
UINT uiMask1, uiMask2 = 0, bBold = hb_parl( 3 );
#ifndef _WIN64
hb_retl( TreeView_GetItemState( ( HWND ) hb_parnl( 1 ), ( HTREEITEM ) hb_parnl( 2 ), &uiMask1 ) );
#else
hb_retl( TreeView_GetItemState( ( HWND ) hb_parnll( 1 ), ( HTREEITEM ) hb_parnll( 2 ), &uiMask1 ) );
#endif
if( bBold )
uiMask2 = TVIS_BOLD;
else
uiMask1 = uiMask1 ^ TVIS_BOLD;
#ifndef _WIN64
TreeView_SetItemState( ( HWND ) hb_parnl( 1 ), ( HTREEITEM ) hb_parnl( 2 ), uiMask1, uiMask2 );
#else
TreeView_SetItemState( ( HWND ) hb_parnll( 1 ), ( HTREEITEM ) hb_parnll( 2 ), uiMask1, uiMask2 );
#endif
hb_retl( uiMask1 & TVIS_BOLD );
}
//-------------------------------------------------------------------------//