Unit ExtListView

Standard defines for all Delphi Free Stuff components } {.$DEFINE DFS_DEBUG} {.$DEFINE DFS_TRY_BACKGROUND_IMAGE} {.$DEFINE DFS_TRY_INFOTIP} {------------------------------------------------------------------------------} { TExtListView v3.05 } {------------------------------------------------------------------------------} { A list view control that enables access to the new style types provieded } { by the updated list view control. The updated list view is provided in } { the COMCTL32.DLL file that comes with Microsoft's new internet software. } { Copyright 1998, Brad Stowers. All Rights Reserved. } { This component can be freely used and distributed in commercial and private } { environments, provied this notice is not modified in any way. } {------------------------------------------------------------------------------} { Feel free to contact me if you have any questions, comments or suggestions } { at bstowers@pobox.com. } { The lateset version will always be available on the web at: } { http://www.pobox.com/~bstowers/delphi/ } { See ELV.txt for notes, known issues, and revision history. } {------------------------------------------------------------------------------} { Date last modified: June 10, 1998 } {------------------------------------------------------------------------------} // C++Builder 3 requires this if you use run-time packages.

Classes

TELVBackgroundImage - forward declaration } // Class for BackgroundImage property
TExtListColumn -
TExtListColumns -
TExtListView - The new class.
TExtLVSaveSettings - Class for saved settings

Functions

CheckDLLVersion - You may find this function useful in install programs and such.
ListView_ApproximateViewRect -
ListView_GetBkImage -
ListView_GetCheckState -
ListView_GetColumnEx - These functions already exist, and there is no way to override them, so I'll just rename them and you can use them as best you can.
ListView_GetColumnOrderArray -
ListView_GetExtendedListViewStyle -
ListView_GetHeader -
ListView_GetHotCursor -
ListView_GetHotItem -
ListView_GetHoverTime -
ListView_GetSelectionMark -
ListView_GetToolTips -
ListView_InsertColumnEx -
ListView_SetBkImage -
ListView_SetCheckState -
ListView_SetColumnEx -
ListView_SetColumnOrderArray -
ListView_SetExtendedListViewStyle - optional wParam = mask
ListView_SetExtendedListViewStyleEx - Pass the LVS_EX_* styles you want to modify in Mask and ExStyle will apply only to those.
ListView_SetHotCursor -
ListView_SetHotItem -
ListView_SetHoverTime -
ListView_SetIconSpacing - -1 for cx and cy means we'll use the default (system settings) 0 for cx or cy means use the current setting (allows you to change just one param
ListView_SetItemCountEx -
ListView_SetSelectionMark -
ListView_SetToolTips -
ListView_SetWorkArea -
ListView_SubItemHitTestEx - C++B 3 users don't need this because their COMMCTRL.

Types

PLVBkImage
PLVBkImageA
PLVBkImageW
PLVDispInfoEx
PLVHitTestInfoEx
PLVItemEx
PNMCacheHint
PNMFindItem
PNMLVGetInfoTip
PNMLVGetInfoTipA
PNMLVGetInfoTipW
PNMODStateChange
TColumnImageAlign
TLVBkImage
TLVBkImageA
TLVBkImageW
TLVColumnEx
TLVDispInfo
TLVDispInfoEx
TLVExtendedStyle
TLVExtendedStyles
TLVHitTestInfoEx
TLVHotTrackEvent
TLVInfoTipEvent
TLVItemActivateEvent
TLVItemCountFlag
TLVItemCountFlags
TLVItemEx
TLVMarqueeBeginEvent
TLVVMCacheHintEvent
TLVVMFindItemEvent
TLVVMGetItemInfoEvent
TLVVMMaskItem
TLVVMMaskItems
TLVVMStateChangedEvent
TNMCacheHint
TNMFindItem
TNMLVGetInfoTip
TNMLVGetInfoTipA
TNMLVGetInfoTipW
TNMODStateChange

Constants

DFS_COMPONENT_VERSION
ELV_NO_SUBITEM_IMAGE
LVBKIF_SOURCE_HBITMAP
LVBKIF_SOURCE_MASK
LVBKIF_SOURCE_NONE
LVBKIF_SOURCE_URL
LVBKIF_STYLE_MASK
LVBKIF_STYLE_NORMAL
LVBKIF_STYLE_TILE
LVCFMT_BITMAP_ON_RIGHT
LVCFMT_COL_HAS_IMAGES
LVCFMT_IMAGE
LVCF_IMAGE
LVCF_ORDER
LVGIT_UNFOLDED
LVIF_INDENT
LVIF_NORECOMPUTE
LVIS_ACTIVATING
LVM_APPROXIMATEVIEWRECT
LVM_GETBKIMAGE
LVM_GETBKIMAGEA
LVM_GETBKIMAGEW
LVM_GETCOLUMNORDERARRAY
LVM_GETEXTENDEDLISTVIEWSTYLE
LVM_GETHEADER
LVM_GETHOTCURSOR
LVM_GETHOTITEM
LVM_GETHOVERTIME
LVM_GETSELECTIONMARK
LVM_GETTOOLTIPS
LVM_SETBKIMAGE
LVM_SETBKIMAGEA
LVM_SETBKIMAGEW
LVM_SETCOLUMNORDERARRAY
LVM_SETEXTENDEDLISTVIEWSTYLE
LVM_SETHOTCURSOR
LVM_SETHOTITEM
LVM_SETHOVERTIME
LVM_SETICONSPACING
LVM_SETSELECTIONMARK
LVM_SETTOOLTIPS
LVM_SETWORKAREA
LVN_GETINFOTIP
LVN_GETINFOTIPA
LVN_GETINFOTIPW
LVN_HOTTRACK
LVN_ITEMACTIVATE
LVN_MARQUEEBEGIN
LVN_ODCACHEHINT
LVN_ODFINDITEM
LVN_ODFINDITEMA
LVN_ODFINDITEMW
LVN_ODSTATECHANGED
LVSICF_NOINVALIDATEALL
LVSICF_NOSCROLL
LVS_EX_CHECKBOXES
LVS_EX_FLATSB
LVS_EX_FULLROWSELECT
LVS_EX_GRIDLINES
LVS_EX_HEADERDRAGDROP
LVS_EX_INFOTIP
LVS_EX_MULTIWORKAREAS
LVS_EX_ONECLICKACTIVATE
LVS_EX_REGIONAL
LVS_EX_SUBITEMIMAGES
LVS_EX_TRACKSELECT
LVS_EX_TWOCLICKACTIVATE
LVS_EX_UNDERLINECOLD
LVS_EX_UNDERLINEHOT
LVS_OWNERDATA

Variables


Functions


function CheckDLLVersion(const DLLName: string; MajorHi, MajorLo, MinorHi, MinorLo: word): boolean;

You may find this function useful in install programs and such. Example of usage is: if not CheckDLLVersion('COMCTL32.DLL', 4, 70, 0, 0) then .... which returns TRUE if COMCTL32.DLL is version 4.70.0.0 or higher.

function ListView_ApproximateViewRect(LVWnd: HWnd; Width, Height, Count: integer): DWORD;


function ListView_GetBkImage(LVWnd: HWnd; plvbki: PLVBkImage): BOOL;


function ListView_GetCheckState(LVWnd: HWnd; Index: UINT): boolean;


function ListView_GetColumnEx(LVWnd: HWND; iCol: Integer; var pcol: TLVColumnEx): Bool;

These functions already exist, and there is no way to override them, so I'll just rename them and you can use them as best you can.

function ListView_GetColumnOrderArray(LVWnd: HWnd; Count: integer; IntArray: PIntArray): boolean;


function ListView_GetExtendedListViewStyle(LVWnd: HWnd): DWORD;


function ListView_GetHeader(LVWnd: HWnd): HWnd;


function ListView_GetHotCursor(LVWnd: HWnd): HCursor;


function ListView_GetHotItem(LVWnd: HWnd): integer;


function ListView_GetHoverTime(LVWnd: HWnd): DWORD;


function ListView_GetSelectionMark(LVWnd: HWnd): integer;


function ListView_GetToolTips(LVWnd: HWnd): HWnd;


function ListView_InsertColumnEx(LVWnd: HWND; iCol: Integer; const pcol: TLVColumnEx): Integer;


function ListView_SetBkImage(LVWnd: HWnd; plvbki: PLVBkImage): BOOL;


procedure ListView_SetCheckState(LVWnd: HWnd; Index: UINT; Checked: boolean);


function ListView_SetColumnEx(LVWnd: HWnd; iCol: Integer; const pcol: TLVColumnEx): Bool;


function ListView_SetColumnOrderArray(LVWnd: HWnd; Count: integer; IntArray: PIntArray): boolean;


function ListView_SetExtendedListViewStyle(LVWnd: HWnd; ExStyle: LPARAM): DWORD;

optional wParam = mask

function ListView_SetExtendedListViewStyleEx(LVWnd: HWnd; Mask: DWord; ExStyle: LPARAM): DWORD;

Pass the LVS_EX_* styles you want to modify in Mask and ExStyle will apply only to those. Others will be left in current state. For example, if you pass LVS_EX_FULLROWSELECT for Mask and 0 for ExStyle, the LVS_EX_FULLROWSELECT style will be cleared, but all other styles will remain the same.

function ListView_SetHotCursor(LVWnd: HWnd; Cursor: HCursor): HCursor;


function ListView_SetHotItem(LVWnd: HWnd; Item: integer): integer;


function ListView_SetHoverTime(LVWnd: HWnd; dwHoverTimeMS: DWORD): DWORD;


function ListView_SetIconSpacing(LVWnd: HWnd; cx, cy: integer): DWORD;

-1 for cx and cy means we'll use the default (system settings) 0 for cx or cy means use the current setting (allows you to change just one param

procedure ListView_SetItemCountEx(LVWnd: HWnd; Items: integer; Flags: DWORD);


function ListView_SetSelectionMark(LVWnd: HWnd; iIndex: integer): integer;


function ListView_SetToolTips(LVWnd, NewWnd: HWnd): HWnd;


function ListView_SetWorkArea(LVWnd: HWnd; const Rect: TRect): boolean;


function ListView_SubItemHitTestEx(LVWnd: HWnd; var HitTestInfo: TLVHitTestInfoEx): integer;

C++B 3 users don't need this because their COMMCTRL.PAS file has it write and they can simply use the existing TLVHitTestInfo and ListView_SubItemHitTest

Types


PLVBkImage = PLVBkImageA

PLVBkImageA = ^TLVBkImageA

PLVBkImageW = ^TLVBkImageW

PLVDispInfoEx = ^TLVDispInfoEx

PLVHitTestInfoEx = ^TLVHitTestInfoEx
C++B 3 users don't need this because their COMMCTRL.PAS file has it write and they can simply use the existing TLVHitTestInfo and ListView_SubItemHitTest(
PLVItemEx = ^TLVItemEx

PNMCacheHint = ^TNMCacheHint

PNMFindItem = ^TNMFindItem

PNMLVGetInfoTip = PNMLVGetInfoTipA

PNMLVGetInfoTipA = ^TNMLVGetInfoTipA

PNMLVGetInfoTipW = ^TNMLVGetInfoTipW

PNMODStateChange = ^TNMODStateChange

TColumnImageAlign = (ciaLeftOfText, ciaRightOfText);

TLVBkImage = TLVBkImageA

TLVBkImageA = record
ulFlags : ULONG;
hbm : HBITMAP;
pszImage : PChar;
cchImageMax : UINT;
xOffsetPercent : integer;
yOffsetPercent : integer;
end;

TLVBkImageW = record
ulFlags : ULONG;
hbm : HBITMAP;
pszImage : PWideChar;
cchImageMax : UINT;
xOffsetPercent : integer;
yOffsetPercent : integer;
end;

TLVColumnEx = record
mask : UINT;
fmt : Integer;
cx : Integer;
pszText : PAnsiChar;
cchTextMax : Integer;
iSubItem : Integer;
iImage : integer;
iOrder : integer;
end;

TLVDispInfo = TLVDispInfoA

TLVDispInfoEx = record
hdr : TNMHDR;
item : TLVItemEx;
end;

TLVExtendedStyle = (lvxGridLines, lvxSubItemImages, lvxCheckboxes,
     lvxTrackSelect, lvxHeaderDragDrop, lvxFullRowSelect, lvxOneClickActivate,
     lvxTwoClickActivate, lvxFlatScrollBar,
                                                  
     lvxUnderlineHot, lvxUnderlineCold);
New extended style flags converted to set format (RPM = Report Mode Only). lvxGridlines: Adds grid lines to seperate items and columns. RPM lvxSubItemImages: Allows images to be displayed for subitems. RPM lvxCheckboxes: Adds checkboxes to items. Checked items are stored internally as selected items. lvxTrackSelect: Tracks the mouse and highlights the item it currently positioned over by changing it's color. If mouse is left over an item for a brief period of time, it will be automatically selected. lvxHeaderDragDrop: Allows headers to be dragged to new positions and dropped, allowing users to reorder column information. lvxFullRowSelect: Allows user to click anywhere on an item to select it, highlighting the entire length of the item. Without this style, users must click inside the text of column 0. It is only useful in vsReport view style. lvxOneClickActivate: Sends an LVN_ITEMACTIVATE notification message to the parent when the user clicks an item. lvxTwoClickActivate: Sends an LVN_ITEMACTIVATE notification message to the parent when the user double clicks an item. lvxFlatScrollBar: Enables flat scroll bars in the list view. lvxInfoTip: Enables the OnInfoTip event that allows notification and/or modification of a tooltip before it is displayed. Only allowed for vsIcon ViewStyle. lvxUnderlineHot: Causes hot items to be displayed with underlined text. This style is ignored if lvxOneClickActivate or lvxTwoClickActivate is not set. lvxUnderlineCold: Causes nonhot items to be displayed with underlined text. This style is ignored if lvxOneClickActivate is not set.
TLVExtendedStyles = set of TLVExtendedStyle
A set of the new style bits.
TLVHitTestInfoEx = record
pt : TPoint;
flags : UINT;
iItem : integer;
iSubItem : integer;
end;

TLVHotTrackEvent = procedure(Sender: TObject; var ItemIndex: integer;
     SubItemIndex: integer; Location: TPoint;
     var AllowSelect: boolean) of object

TLVInfoTipEvent = procedure(Sender: TObject; ItemIndex: integer;
     Current: string; var Additional: string) of object

TLVItemActivateEvent = TNotifyEvent

TLVItemCountFlag = (lvsicfNoInvalidateAll, lvsicfNoScroll);

TLVItemCountFlags = set of TLVItemCountFlag

TLVItemEx = record
mask : UINT;
iItem : Integer;
iSubItem : Integer;
state : UINT;
stateMask : UINT;
pszText : PAnsiChar;
cchTextMax : Integer;
iImage : Integer;
lParam : LPARAM;
iIndent : integer;
end;

TLVMarqueeBeginEvent = procedure(Sender: TObject;
     var CanBegin: boolean) of object

TLVVMCacheHintEvent = procedure(Sender: TObject;
     var HintInfo: TNMCacheHint) of object

TLVVMFindItemEvent = procedure(Sender: TObject; var FindInfo: TNMFindItem;
     var Found: integer) of object

TLVVMGetItemInfoEvent = procedure(Sender: TObject; Item, SubItem: integer;
     Mask: TLVVMMaskItems; var Image: integer; var Param: LPARAM;
     var State: UINT; var Indent: integer; var Text: string) of object

TLVVMMaskItem = (lvifText, lvifImage, lvifParam, lvifState, lvifIndent);

TLVVMMaskItems = set of TLVVMMaskItem

TLVVMStateChangedEvent = procedure(Sender: TObject;
     var StateInfo: TNMODStateChange) of object

TNMCacheHint = record
hdr : TNMHDR;
iFrom : integer;
iTo : integer;
end;

TNMFindItem = record
hdr : TNMHDR;
iStart : integer;
lvif : TLVFindInfo;
end;

TNMLVGetInfoTip = TNMLVGetInfoTipA

TNMLVGetInfoTipA = record
hdr : TNMHDR;
dwFlags : DWORD;
pszText : PChar;
cchTextMax : integer;
iItem : integer;
iSubItem : integer;
lParam : LPARAM;
end;

TNMLVGetInfoTipW = record
hdr : TNMHDR;
dwFlags : DWORD;
pszText : PWideChar;
cchTextMax : integer;
iItem : integer;
iSubItem : integer;
lParam : LPARAM;
end;

TNMODStateChange = record
hdr : TNMHDR;
iFrom : integer;
iTo : integer;
uNewState : UINT;
uOldState : UINT;
end;

Constants

DFS_COMPONENT_VERSION = 'TExtListView v3.05'

ELV_NO_SUBITEM_IMAGE = MAXINT - 1

Setting a subitem image (lvxSubItemImages ExtendStyle) to -1 does not properly clear the image for the subitem. The current COMCTL32.DLL implementation does not seem to store this value and instead it gets a random value assigned to it. The work-around that I have found is to set the index to a value that does not exist in the image list. To make this a bit easier, I have declared this constant. Assigning this value to SubItem_ImageIndex[itemindex] will clear the image from the subitem as long as your image list does not have more than 2,147,483,646 images in it. :

LVBKIF_SOURCE_HBITMAP = $00000001

LVBKIF_SOURCE_MASK = $00000003

LVBKIF_SOURCE_NONE = $00000000

LVBKIF_SOURCE_URL = $00000002

LVBKIF_STYLE_MASK = $00000010

LVBKIF_STYLE_NORMAL = $00000000

LVBKIF_STYLE_TILE = $00000010

LVCFMT_BITMAP_ON_RIGHT = $1000

Item displays an image from an image list.

LVCFMT_COL_HAS_IMAGES = $8000

Image appears to right of text.

LVCFMT_IMAGE = $0800

LVCF_IMAGE = $0010

LVCF_ORDER = $0020

LVGIT_UNFOLDED = $0001

NMLVGETINFOTIPA.dwFlag values

LVIF_INDENT = $0010

Borland forgot this one. {$IFNDEF DFS_CPPB_3_UP

LVIF_NORECOMPUTE = $0800

LVIS_ACTIVATING = $0020

Undocumented.

LVM_APPROXIMATEVIEWRECT = LVM_FIRST + 64

LVM_GETBKIMAGE = LVM_GETBKIMAGEA

LVM_GETBKIMAGEA = (LVM_FIRST + 69)

LVM_GETBKIMAGEW = (LVM_FIRST + 139)

LVM_GETCOLUMNORDERARRAY = LVM_FIRST + 59

LVM_GETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 55

LVM_GETHEADER = LVM_FIRST + 31

LVM_GETHOTCURSOR = LVM_FIRST + 63

LVM_GETHOTITEM = LVM_FIRST + 61

LVM_GETHOVERTIME = (LVM_FIRST + 72)

LVM_GETSELECTIONMARK = (LVM_FIRST + 66)

LVM_GETTOOLTIPS = (LVM_FIRST + 78)

LVM_SETBKIMAGE = LVM_SETBKIMAGEA

LVM_SETBKIMAGEA = (LVM_FIRST + 68)

LVM_SETBKIMAGEW = (LVM_FIRST + 138)

LVM_SETCOLUMNORDERARRAY = LVM_FIRST + 58

LVM_SETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 54

LVM_SETHOTCURSOR = LVM_FIRST + 62

LVM_SETHOTITEM = LVM_FIRST + 60

LVM_SETHOVERTIME = (LVM_FIRST + 71)

LVM_SETICONSPACING = LVM_FIRST + 53

LVM_SETSELECTIONMARK = (LVM_FIRST + 67)

LVM_SETTOOLTIPS = (LVM_FIRST + 74)

LVM_SETWORKAREA = LVM_FIRST + 65

LVN_GETINFOTIP = LVN_GETINFOTIPA

LVN_GETINFOTIPA = (LVN_FIRST-57)

LVN_GETINFOTIPW = (LVN_FIRST-58)

LVN_HOTTRACK = (LVN_FIRST-21)

LVN_ITEMACTIVATE = LVN_FIRST-14

LVN_MARQUEEBEGIN = LVN_FIRST-56

LVN_ODCACHEHINT = LVN_FIRST-13

Specifies a "virtual" control. New notification messages.

LVN_ODFINDITEM = LVN_ODFINDITEMA

LVN_ODFINDITEMA = LVN_FIRST-52

LVN_ODFINDITEMW = LVN_FIRST-79

LVN_ODSTATECHANGED = LVN_FIRST-15

LVSICF_NOINVALIDATEALL = $00000001

LVSICF_NOSCROLL = $00000002

LVS_EX_CHECKBOXES = $00000004

Report mode only.

LVS_EX_FLATSB = $00000100

These were already defined in everything... const LVIR_BOUNDS = 0; LVIR_ICON = 1; LVIR_LABEL = 2; LVIR_SELECTBOUNDS = 3; *) {$IFNDEF DFS_CPPB_3_UP

LVS_EX_FULLROWSELECT = $00000020

Report mode only.

LVS_EX_GRIDLINES = $00000001

LVS_EX_HEADERDRAGDROP = $00000010

LVS_EX_INFOTIP = $00000400

LVS_EX_MULTIWORKAREAS = $00002000

LVS_EX_ONECLICKACTIVATE = $00000040

Report mode only.

LVS_EX_REGIONAL = $00000200

LVS_EX_SUBITEMIMAGES = $00000002

Report mode only.

LVS_EX_TRACKSELECT = $00000008

LVS_EX_TWOCLICKACTIVATE = $00000080

LVS_EX_UNDERLINECOLD = $00001000

LVS_EX_UNDERLINEHOT = $00000800

LVS_OWNERDATA = $1000

New list view style flags.

Variables