PureLVSORT+ library
Overview
Automatically sorts listicon gadgets after a LVN_COLUMNCLICK event (click on column header) or a PureLVSORT_SortListIconNow() function call.Functions
PureLVSORT_SelectGadgetToSort(GadgetNumber.l, ShowClickedHeader.l)Select new ListIconGadget to sort.PureLVSORT_ClearGadget(GadgetNumber.l)
ShowClickedHeader :
#PureLVSORT_ShowClickedHeader_No --> don't modify the clicked header
#PureLVSORT_ShowClickedHeader_Text --> clicked header is modified like "« HEADER »" / "» HEADER «"
according to sorting direction : +1 / -1
#PureLVSORT_ShowClickedHeader_IconLeft --> clicked header is modified like "^ HEADER" / "v HEADER" (where ^ and v are icons)
according to sorting direction : +1 / -1
#PureLVSORT_ShowClickedHeader_IconRight --> clicked header is modified like "HEADER ^" / "HEADER v" (where ^ and v are icons)
according to sorting direction : +1 / -1
Return codes :
#PureLVSORT_Ok ; Success
#PureLVSORT_NotAGadget ; Specified gadget does not exist
#PureLVSORT_MemoryAllocationProblem ; Memory allocation failed
#PureLVSORT_UndefinedGadget ; Specified gadget was not initialized with PureLVSORT_SelectGadgetToSort()
Don't sort ListIconGadget anymore (if click on column header).PureLVSORT_SortListIconNow(ListIconGadget.l, ListIconColumn.l, SortDirection.l)
This function simulates a LVN_COLUMNCLICK event for the specified gadgetPureLVSORT_DefineAlphabeticOrder(*UserArray)
SortDirection : +1 / -1
Initialize gadget with PureLVSORT_SelectGadgetToSort().
Set alphabetic order for column type #PureLVSORT_Alphabetic_User.PureLVSORT_DefineUserCallback(*UserCallbackAddress)
*UserArray is a pointer to a 256 characters array, defining the sorting order for the 256 ASCII codes.
Character 0 : sorting order for ASCII code 0, ..., character 65 : sorting order for ASCII code 65 "A", ..., character 255 : sorting order for ASCII code 255.
Warning : this function must be called before setting a #PureLVSORT_Alphabetic_User column type.
Define user sorting callback for column type #PureLVSORT_UserCallback.PureLVSORT_SetColumnType(GadgetNumber.l, Column.l, ColumnType.b)
The callback is a procedure called when a ListIconGadget is sorted.
The callback procedure is like this :
Procedure MySortingCallback(ListIconNumber.l, ListIconColumn.l, Item1.s, Item2.s)
;
Compare Item1 and Item2 and
Return 1 if Item1 > Item2
Return -1 if Item1 < Item2
Return 0 if Item1 = Item2
;
EndProcedure
declared like that :
PureLVSORT_DefineUserCallback(@MySortingCallback())
where :
ListIconNumber is the purebasic gadget ID
ListIconColumn is the sorted column
Item1 and Item2 are the items to sort.
Warning : this function must be called before setting a #PureLVSORT_UserCallback column type.
Set column type.PureLVSORT_SetColumnAlignment(GadgetNumber.l, Column.l, Alignment.l)
ColumnType :
#PureLVSORT_String [DEFAULT] ; example : "ABCDE" (case insensitive)
#PureLVSORT_String_CaseSensitive ; example : "aDECd"
#PureLVSORT_Numeric ; example : "-1523"
#PureLVSORT_Numeric_Quad ; example : "5219842514"
#PureLVSORT_Float ; example : "0.25"
#PureLVSORT_Float_Double ; example : "3.1415926"
#PureLVSORT_DateDDMMYYYY ; example : "31/12/2003"
#PureLVSORT_DateMMDDYYYY ; example : "12/31/2003"
#PureLVSORT_DateDDMMYYYYHHMMSS ; example : "31/12/2003 12:31:21"
#PureLVSORT_DateDDMMYYHHMM ; example : "31/12/03 12:31"
#PureLVSORT_FileSize ; examples : "1.23 GB", "235.51 MB", "1021 KB"
#PureLVSORT_NoSorting ; column is locked (no sorting after a LVN_COLUMNCLICK event)
#PureLVSORT_Alphabetic_User ; sorting order is defined by a user byte array [PureLVSORT_DefineAlphabeticOrder()]
#PureLVSORT_UserCallback ; sorting order is defined by a user callback [PureLVSORT_DefineUserCallback()]
Initialize gadget with PureLVSORT_SelectGadgetToSort().
Specifies the alignment of the column heading and the subitem text in the column.PureLVSORT_SetColumnWidth(GadgetNumber.l, Column.l, width.l)
Possible values :
#PureLVSORT_Center Text is centered;
#PureLVSORT_Left Text is left-aligned;
#PureLVSORT_Right Text is right-aligned.
Set ListIcon column width in list view coordinates, or one of the following values :PureLVSORT_SetUserIcons(IconArrowUpHandle.l, IconArrowDownHandle.l)
#PureLVSORT_AutoSize Automatically sizes the column;
#PureLVSORT_UseHeader Automatically sizes the column to fit the header text.
Define 12x12 user icons.PureLVSORT_UseNativeWindowsIcons(TrueOfFalse.l)
IconArrowUpHandle and IconArrowDownHandle are icon or bitmap handles.
Enable or disable 'native' windows sorting icons.PureLVSORT_GetSortingDirection(GadgetNumber.l)
Notes :
- this feature requires Windows XP minimum with themes enabled and 'XP skin support' checked in compiler options ;
- the 'native' icon is always to the right ;
- if PureLVSORT doesn't detect themes support, it will use its own default icons.
Get last clicked column sorting direction for the gadget.PureLVSORT_GetClickedColumn(GadgetNumber.l)
Returns +1/-1, or 0 if no column was clicked.
Get last clicked column number for the gadget.PureLVSORT_SetColumnFlag(GadgetNumber.l, Column.l, ColumnFlag.b)
Returns -1 if no column was clicked.
Set a column flag.PureLVSORT_ResetColumnFlag(GadgetNumber.l, Column.l, ColumnFlag.b)
Flags :
#PureLVSORT_Column_Fixed : the column width is fixed
#PureLVSORT_Column_Hidden : the column is hidden
Initialize gadget with PureLVSORT_SelectGadgetToSort().
Reset a column flag set with PureLVSORT_SetColumnFlag().PureLVSORT_LoadListIcon(GadgetNumber.l, FileName.s)
Flags :
#PureLVSORT_Column_Fixed
#PureLVSORT_Column_Hidden
Load ListIcon content saved with PureLVSORT_SaveListIcon().PureLVSORT_LoadListIconTXT(GadgetNumber.l, FileName.s)
Returns #False if failed.
Load ListIcon content from a text file (saved with PureLVSORT_SaveListIconTXT()).PureLVSORT_LoadListIconFromMem(GadgetNumber.l, *Buffer, FilterString.s, FilterColumn.l, CaseInsensitive.l)
Returns #False if failed.
Load ListIcon items from memory with a filter.PureLVSORT_SaveListIcon(GadgetNumber.l, FileName.s)
If FilterString = "", all items are loaded.
Returns #False if failed.
The items must have been saved with the PureLVSORT_SaveListIconToMem() function.
It's a very useful function for filtering ; see example below :
Save ListIcon content to a file (compressed with JCalG1 algorithm).PureLVSORT_SaveListIconTXT(GadgetNumber.l, FileName.s)
Returns #False if failed.
Save ListIcon content to a text file (column separator is TAB [chr(9)]).PureLVSORT_SaveListIconToMem(GadgetNumber.l)
Returns #False if failed.
Save the ListIcon items to memory.PureLVSORT_FreeListIconBuffer(*ListIconBuffer)
Returns the memory address or #False if failed.
It's the programmer's responsability to release the memory using PureLVSORT_FreeListIconBuffer()..
It's a very useful function for filtering ; see the PureLVSORT_LoadListIconFromMem() function for more details
Free the memory allocated with PureLVSORT_SaveListIconToMem().PureLVSORT_SetFilter(GadgetNumber.l)
Enables a filterbar as part of the standard header for the ListIcon.PureLVSORT_SetFilterTimeOut(FilterTimeOut)
If a cell content matches with the entered filterbar value (in the same column), the
library will select the corresponding line and ensure it is visible.
Initialize gadget with PureLVSORT_SelectGadgetToSort().
Note
There are some cosmetic glitches if the sorting icons are activated at the same time
(options #PureLVSORT_ShowClickedHeader_IconLeft/Right).
If this is inacceptable, you can use #PureLVSORT_ShowClickedHeader_No/Text
before activating the filterbar and restore the icons when disabling the filterbar.
Set filter change timeout in ms [default is 1000].PureLVSORT_ResetFilter(GadgetNumber.l)
Must be called before PureLVSORT_SetFilter().
Disables the filterbar in the ListIcon header.PureLVSORT_SetFilterString(GadgetNumber.l, Column.l, FilterString.s)
Set the filter string for a ListIcon column.PureLVSORT_GetFilterString(GadgetNumber.l, Column.l)
The filter mode is activated with the PureLVSORT_SetFilter() function.
Get the filter string for a ListIcon column.PureLVSORT_DefineFilterCallback(*UserCallbackAddress)
The filter mode is activated with the PureLVSORT_SetFilter() function.
Define user filtering callback for #HDN_FILTERCHANGE or #HDN_FILTERBTNCLICK events.PureLVSORT_MakeColumnEditable(GadgetNumber.l, Column.l, TrueOrFalse.l)
The callback is a procedure called when a listicon header filter changes (#HDN_FILTERCHANGE) or a header button is pressed (#HDN_FILTERBTNCLICK).
The filter mode is activated with the PureLVSORT_SetFilter() function.
The callback procedure is like this :
Procedure MyFilterCallback(GadgetNumber.l, FilterString.s, ListIconColumn.l, EventID.l)
; ...
EndProcedure
declared like that :
PureLVSORT_DefineFilterCallback(@MyFilterCallback())
where :
GadgetNumber is the purebasic gadget ID
FilterString is the header filter text
ListIconColumn is the header column
EventID is the trigger event (#PureLVSORT_FilterBtnClick or #PureLVSORT_FilterChange)
Make a a listicon column editable.PureLVSORT_SetEditingCallback(*ProcedureAddress)
The user can modify the cell content by double-clicking on the cell.
By default, the user edits the cell like a stringgadget.
By defining an editing callback with PureLVSORT_SetEditingCallback(), you can control some editing features.
Set a cell editing callback.PureLVSORT_SetEditingColors(TextColor.l, BackColor.l)
The callback is a procedure like this :
Procedure.l MyEditCallback(Event.l, ListIconNumber.l, Column.l, Row.l, Text.s)
Select Event
Case #PureLVSORT_EditStart
; Return : - 0 to enable stringgadget (default)
; - *string to enable a spingadget [the string holds the choice items (separator = '|']
Case #PureLVSORT_EditText
; Return : - 0 to keep the text (default)
; - *string to change the text [the string holds the changed text]
Case #PureLVSORT_EditEnd
Case #PureLVSORT_EditEscape
EndSelect
EndProcedure
Where :
Event is the editing event :
. #PureLVSORT_EditStart : the user starts editing a cell (return a *string to enable a spingadget [the string holds the choice items])
. #PureLVSORT_EditText : the user is editing the cell text (return a *string to change the text [the string holds the changed text])
. #PureLVSORT_EditEnd : edit mode is ending
. #PureLVSORT_EditEscape : edit mode has been cancelled
ListIconNumber is the listicon gadget number
Column is the listicon gadget column
Row is the listicon gadget row
Text is the current cell text
And is defined like this :
PureLVSORT_SetEditingCallback(@MyEditCallback())
Define the cell color while in edit mode.PureLVSORT_CancelCellEditing()
TextColor : text color
BackColor : background color
Cancel any current cell editing (and discard changes).PureLVSORT_ExitCellEditing()
Exit current cell editing (if any) and keep the current cell value.PureLVSORT_CountColumns(GadgetNumber.l)
Count the columns in a ListIcon.PureLVSORT_GetClickedCellRow()
Returns -1 if failed.
Get the listicon clicked cell row after a click event.PureLVSORT_GetClickedCellColumn()
Events
#PB_EventType_LeftClick
#PB_EventType_LeftDoubleClick
#PB_EventType_RightClick
#PB_EventType_RightDoubleClick
Returned values
- Row [>= 0]
- Error : empty row [-1]
Get the listicon clicked cell column after a click event.PureLVSORT_SetLastColumnAutoResize(GadgetNumber.l, TrueOrFalse.l)
Events
#PB_EventType_LeftClick
#PB_EventType_LeftDoubleClick
#PB_EventType_RightClick
#PB_EventType_RightDoubleClick
Returned values
- Column [>= 0]
- Error : empty column [-1]
Resize the last column when the ListIcon is resized.PureLVSORT_ScrollToRow(GadgetNumber.l, Row.l)
Scroll the ListiconGadget to the given row (make it visible at the top of the list).PureLVSORT_Disabled(Disabled.l)
Disable or enable PureLVSORT functions.
This may be handy when you have to add / remove a lot of data to / from a listicongadget : it's faster if PureLVSORT is disabled.