{ ====================================================================
(C) Copyright 2000 FORTH, Inc. Rick VanNorman rvn@forth.com
A listview derrived class skeleton
Added Set Item Tools 3/8/2005 Mike Ghan
==================================================================== }
LVM_FIRST 54 + CONSTANT LVM_SETEXTENDEDLISTVIEWSTYLES
$00000001 CONSTANT LVS_EX_GRIDLINES
$00000100 CONSTANT LVS_EX_FLATSB
$00004000 CONSTANT LVS_EX_LABELTIP \ Unfold partly hidden labels
\ ----- Define a ListView item structure
CLASS tagLV_ITEM
VARIABLE .mask \ bit flags specifying attributes of this data structure
VARIABLE .iItem \ zero-based index of the item referred to by this structure
VARIABLE .iSubItem \ one-based index of the subitem or zero if referring to item
VARIABLE .state \ current state of referred item
VARIABLE .stateMask \ specifies the bits of the state member that are valid
VARIABLE .pszText \ ptr to null-terminated string that contains the item text
VARIABLE .cchTextMax \ size of the buffer pointed to by pszText
VARIABLE .iImage \ index of the listview item's icon within the icon image lists
VARIABLE .lParam \ lparam associated with the item
VARIABLE .iIndent \ Number of image widths to indent the item
END-CLASS
\ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
CLASS tagLV_COLUMN
VARIABLE .mask \ specifies which members of the structure contain valid information
VARIABLE .fmt \ specifies the alignment of the column heading and subitem text in the column
VARIABLE .cx \ specifies the width, in pixels, of the column
VARIABLE .pszText \ pointer to null-terminated string that contains the column heading
VARIABLE .cchTextMax \ specifies the size (in chars) of the buffer pointed to by pszText
VARIABLE .iSubItem \ specifies the index of the sub-item associated with column
VARIABLE .iImage
VARIABLE .iOrder
END-CLASS
\ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
DERRIVEDWINDOW SUBCLASS LISTVIEW-WINDOW
0 WS_TABSTOP OR
WS_CHILD OR
WS_BORDER OR
WS_VISIBLE OR
LVS_AUTOARRANGE OR
LVS_REPORT OR
\ LVS_OWNERDATA OR
LVS_SHOWSELALWAYS OR
CONSTANT STYLE
0 LVS_EX_GRIDLINES
LVS_EX_FLATSB OR
LVS_EX_LABELTIP OR
LVS_EX_FULLROWSELECT OR
CONSTANT EX_STYLE
: MyClass_ClassName ( -- zstr ) Z" SysListView32" ;
: MyWindow_ClassName ( -- z ) MyClass_ClassName ;
: MyWindow_Style ( -- style ) STYLE ;
: MyWindow_Menu ( -- n ) 0 ;
: PreConstruct ;
: PostConstruct
mHWND LVM_SETEXTENDEDLISTVIEWSTYLES NULL EX_STYLE :: SendMessage DROP ( Set Ex Styles )
;
: /COLUMNS ( 'columns -- )
[OBJECTS tagLV_COLUMN MAKES LVC OBJECTS]
LVCF_FMT LVCF_WIDTH OR LVCF_TEXT OR LVCF_SUBITEM OR LVC .mask !
LVCFMT_LEFT LVC .fmt !
( 'cols) 0 BEGIN
OVER @ 0> WHILE OVER @ LVC .cx !
S" Column " PAD ZPLACE DUP (.) PAD ZAPPEND PAD LVC .pszText !
DUP mHWND LVM_INSERTCOLUMNA ROT LVC ADDR :: SendMessage DROP
1+ SWAP CELL+ SWAP
REPEAT 2DROP ;
RECT BUILDS PANE
: RESIZE ( x y cx cy -- ) PANE ADDR !RECT
mHWND PANE ADDR @RECT -1 :: MoveWindow DROP ;
: REBALANCE ( 'balances -- )
@+ ( a n) 0 ?DO
mHWND LVM_SETCOLUMNWIDTH I
3 PICK @ PANE right @ 100 */ :: SendMessage DROP
CELL+
LOOP DROP ;
: SET-#ITEMS ( #items -- )
[OBJECTS tagLV_ITEM MAKES LV_ITEM OBJECTS]
mHWND LVM_DELETEALLITEMS 0 0 :: SendMessage DROP
mHWND LVM_SETITEMCOUNT 2 PICK 0 :: SendMessage DROP
0
?DO mHWND LVM_INSERTITEMA 0 LV_ITEM ADDR :: SendMessage DROP
LOOP ;
: SET-ITEM-TEXT ( addr cnt col row -- )
[OBJECTS tagLV_ITEM MAKES LV_ITEM OBJECTS]
LV_ITEM .iItem !
LV_ITEM .iSubItem !
LVIF_TEXT LV_ITEM .mask !
R-BUF R@ ZPLACE R> LV_ITEM .pszText !
mHWND LVM_SETITEMTEXTA LV_ITEM .iItem @ LV_ITEM ADDR :: SendMessage DROP ;
END-CLASS
\ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
GENERICWINDOW SUBCLASS LVTEST
LISTVIEW-WINDOW BUILDS LVW
: MyClass_ClassName ( -- z ) Z" LVTEST " ;
: MyWindow_WindowName ( -- z ) Z" LVTEST " ;
: MyWindow_Shape ( -- x y cx cy ) 10 10 400 250 ;
CREATE COLUMNS 100 , 60 , 80 , -1 ,
CREATE BALANCES
3 , \ number of columns
25 , 50 , 25 , \ should total 100 %
: RESIZE ( -- )
[OBJECTS RECT MAKES main OBJECTS]
mHWND main ADDR :: GetClientRect DROP
main ADDR @RECT LVW RESIZE BALANCES LVW REBALANCE ;
WM_SIZE MESSAGE: ( -- res ) RESIZE 0 ;
: OnCreate ( -- res )
mHWND LVW ATTACH COLUMNS LVW /COLUMNS RESIZE
10 DUP LVW SET-#ITEMS 0
DO
3 0
DO S" Item " PAD PLACE J (.) PAD APPEND
S" , " PAD APPEND I (.) PAD APPEND
PAD COUNT I J LVW SET-ITEM-TEXT
LOOP
LOOP
0 ;
END-CLASS
LVTEST BUILDS LV-TEST
: GO ( -- ) LV-TEST CONSTRUCT ;
CR .( Type GO for Demo)
CR