PureLVSORT library : sorting ListIconGadgets (and more)

All PureFORM, JaPBe, Libs and useful code maintained by gnozal

Moderator: gnozal

gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

PureLVSORT library : sorting ListIconGadgets (and more)

Post by gnozal »

PureLVSORT library - PB5.1x : V4.51/4.51c (MAR 27th 2013)

Purpose

Code: Select all

Automatically sorts listicon gadgets after a LVN_COLUMNCLICK event (click on column header) or a PureLVSORT_SortListIconNow() function call, and more...
Functions
PB4.xx : http://gnozal.ucoz.com/PureLVSORT_.htm

Example

Code: Select all

#Window_0 = 0
#ListIcon_0 = 0
Procedure Open_Window_0()
  If OpenWindow(#Window_0, 216, 0, 602, 302,  #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "PureLVSORT Test")
    If CreateGadgetList(WindowID())
      ListIconGadget(#ListIcon_0, 5, 5, 590, 285, "String", 110)
      AddGadgetColumn(#ListIcon_0, 1, "Numeric", 110)
      AddGadgetColumn(#ListIcon_0, 2, "Float", 110)
      AddGadgetColumn(#ListIcon_0, 3, "DateDDMMYYYY", 120)
      AddGadgetColumn(#ListIcon_0, 4, "DateMMDDYYYY", 120)
      AddGadgetItem(#ListIcon_0, -1, "ABCDE" + Chr(10) + "514" + Chr(10) + "0.9" + Chr(10) + "31/12/2004" + Chr(10) + "12/31/2004")
      AddGadgetItem(#ListIcon_0, -1, "ACDEF" + Chr(10) + "118" + Chr(10) + "1.9" + Chr(10) + "11/12/2004" + Chr(10) + "12/11/2004")
      AddGadgetItem(#ListIcon_0, -1, "ZABCD" + Chr(10) + "-414" + Chr(10) + "7.0" + Chr(10) + "21/01/2003" + Chr(10) + "01/21/2003")
      AddGadgetItem(#ListIcon_0, -1, "DEFGH" + Chr(10) + "524" + Chr(10) + "900" + Chr(10) + "10/06/2001" + Chr(10) + "06/10/2001")
    EndIf
  EndIf
EndProcedure
Open_Window_0()
; ListIcon Sort Setup
If PureLVSORT_SelectGadgetToSort(#ListIcon_0, #PureLVSORT_ShowClickedHeader_Icon) = #PureLVSORT_Ok
  PureLVSORT_SetColumnType(#ListIcon_0, 0, #PureLVSORT_String) ; default, not necessary
  PureLVSORT_SetColumnType(#ListIcon_0, 1, #PureLVSORT_Numeric)
  PureLVSORT_SetColumnType(#ListIcon_0, 2, #PureLVSORT_Float)
  PureLVSORT_SetColumnType(#ListIcon_0, 3, #PureLVSORT_DateDDMMYYYY)
  PureLVSORT_SetColumnType(#ListIcon_0, 4, #PureLVSORT_DateMMDDYYYY)
EndIf
;
Repeat
  Event = WaitWindowEvent()
  If EventType() = #PB_EventType_LeftDoubleClick 
    PureLVSORT_ClearGadget(#ListIcon_0)
  EndIf
Until Event = #PB_EventCloseWindow
End
Download
Only available for Purebasic Windows x86
PB3.94 : http://gnozal.ucoz.com/PureLVSORT.zip
PB4.0x : http://gnozal.ucoz.com/PureLVSORT_.zip
There are two versions in the archive : PureLVSORT (standard) and PureLVSORT-Plus ; the plus version adds some basic listicon editing functions.
PB4.1x : http://gnozal.ucoz.com/PureLVSORT__.zip
There are two versions in the archive : PureLVSORT (standard) and PureLVSORT-Plus ; the plus version adds some basic listicon editing functions.
PB4.2x : http://gnozal.ucoz.com/PureLVSORT___.zip
There are two versions in the archive : PureLVSORT (standard) and PureLVSORT-Plus ; the plus version adds some basic listicon editing functions.
PB4.3x : http://gnozal.ucoz.com/PureLVSORT_430.zip
There are two versions in the archive : PureLVSORT (standard) and PureLVSORT-Plus ; the plus version adds some basic listicon editing functions.
PB4.4x : http://gnozal.ucoz.com/PureLVSORT_440.zip
There are two versions in the archive : PureLVSORT (standard) and PureLVSORT-Plus ; the plus version adds some basic listicon editing functions.
PB4.5x : http://gnozal.ucoz.com/PureLVSORT_450.zip
There are two versions in the archive : PureLVSORT (standard) and PureLVSORT-Plus ; the plus version adds some basic listicon editing functions.
PB4.6x : http://gnozal.ucoz.com/PureLVSORT_460.zip
There are two versions in the archive : PureLVSORT (standard) and PureLVSORT-Plus ; the plus version adds some basic listicon editing functions.
PB5.0x : http://gnozal.ucoz.com/PureLVSORT_500.zip
There are two versions in the archive : PureLVSORT (standard) and PureLVSORT-Plus ; the plus version adds some basic listicon editing functions.
PB5.1x : http://gnozal.ucoz.com/PureLVSORT_510.zip
There are two versions in the archive : PureLVSORT (standard) and PureLVSORT-Plus ; the plus version adds some basic listicon editing functions.

Notes :
1. The PureLVSORT sorting functions are designed for a multicolumn gadget. If your listicongadget has only one column, add a zero length column or use the #LVS_SORT* styles.
2. PureLVSORT uses the Windows #LVM_SORTITEMS message to sort the listicongadget, and this implies using LV_ITEM\lParam (so the sorting is not compatible with Set/GetGadgetItemData(), or the other way round : the Purebasic listicongadget is not 100% Windows API compatible : it's not a simple SysListView32).

_________________
For tools, jaPBe plugins and libs, visit http://gnozal.ucoz.com/
Last edited by gnozal on Tue Aug 18, 2009 11:50 am, edited 55 times in total.
ebs
Enthusiast
Enthusiast
Posts: 530
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

gnozal,

Your library is GREAT! I've been trying (unsuccessfully) to do this for a while.

Can I make a suggestion? Please consider changing the column sort indicator from "<< HEADER >>" and ">> HEADER <<" to something with up and down arrows, like "HEADER ^" and "HEADER v". I think this makes it easier to understand the sort direction.

Regards,
Eric
zikitrake
Addict
Addict
Posts: 834
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

8O 8O 8O Great library!!!

A suggestion, can you add an option to it so that it does not order a column? (will be:

Code: Select all

PureLVSORT_LockColumn(#ListIcon_0, Num_Col_Locked)
See This "ListIcon" :oops:

Code: Select all

SERVER | BackupName    | State |
----------------------------------------
 Serv1  | S1_WeekA      | Ok    |
       | S1_DailyA     | Ok    |
       | S1_DailyB     | Fail  |
       | S1_DailyC     | Ok    |
I want to maintain "Serv1" (Col "SERVER") always in the first row.


Thank you!


PD: Sorry for my bad bad english
:?
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

ebs wrote:Can I make a suggestion? Please consider changing the column sort indicator from "<< HEADER >>" and ">> HEADER <<" to something with up and down arrows, like "HEADER ^" and "HEADER v". I think this makes it easier to understand the sort direction.
I will have this in mind for the next version (it will be optional)
A suggestion, can you add an option to it so that it does not order a column? (will be: PureLVSORT_LockColumn(#ListIcon_0, Num_Col_Locked)
I will take a look how to do this for the next version.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Library update

- new options for PureLVSORT_SelectGadgetToSort(GadgetNumber.l, ShowClickedHeader.l)

Code: Select all

ShowClickedHeader :   #PureLVSORT_ShowClickedHeader_No
                      #PureLVSORT_ShowClickedHeader_Text
                      #PureLVSORT_ShowClickedHeader_Icon
- new flag for PureLVSORT_SetColumnType(GadgetNumber.l, Column.l, ColumnType.b)

Code: Select all

#PureLVSORT_NoSorting ; column is locked (no sorting after a LVN_COLUMNCLICK event)
ebs
Enthusiast
Enthusiast
Posts: 530
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

gnozal,

I just tried your new version - thanks for the fast turnaround!

The sort direction icon looks good. A few more requests, if I'm not being too pushy: Consider making the up/down icons user-defined, so I can use different icons. Also, allowing the user to specify that the icon should appear before or after the header text would be handy.

The #PureLVSORT_NoSorting sort option seems to be missing from the resident file. It does prevent the specified column from being sorted when its header is clicked. However, I think that zikitrake was asking for a column that would always stay the same, no matter which column header was clicked. Let me know if I've got it wrong.

Regards,
Eric
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

@ebs : thanks, I will see for the next version.
A column that would always stay the same, no matter which column header was clicked : I don't think it's logical :?:
zikitrake
Addict
Addict
Posts: 834
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

ebs wrote:gnozal,
... However, I think that zikitrake was asking for a column that would always stay the same, no matter which column header was clicked. Let me know if I've got it wrong.
Regards,
Eric
It is as ebs says

Yes!, gnozal, I know that it can seem illogical, but for my project I need that it is thus.

:oops: :oops: Sorry for my bad english
Num3
PureBasic Expert
PureBasic Expert
Posts: 2810
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

BUG!!!

Seems that you must define further images with values bigger than 1 or you'll corrupt the internal icons from PureLVSORT_SelectGadgetToSort(#Gadget_main_ListIcon8, #PureLVSORT_ShowClickedHeader_Icon) ...

Here's an example!

Code: Select all

;/ Created with PureVisionXP v2.03
;/ Tue, 07 Dec 2004 14:00:35
;/ by Rui Carvalho


;-Global Variables and Constants
Global BubbleTipStyle.l:BubbleTipStyle=0
#PB_Image_BorderRaised =$1

;-Window Constants
Enumeration 1
  #Window_main
EndEnumeration
#WindowIndex=#PB_Compiler_EnumerationValue


;-Gadget Constants
Enumeration 1
  ;Window_main
 
  #Gadget_main_Panel2
  #Gadget_main_Tab
  #Gadget_main_ListIcon8
  
EndEnumeration

#Image_main_Tab=0 ;<-- 0 or 1 will make 

#GadgetIndex=#PB_Compiler_EnumerationValue

If CreateImage(#Image_main_Tab,16,16)
  StartDrawing(ImageOutput())
  For a=1 To 200
    Plot(Random(16),Random(16))
  Next
EndIf

;-StatusBar Constants
Enumeration 1
  #StatusBar_main
  #StatusBar_main_info1 =0
  #StatusBar_main_info2 =1
EndEnumeration
#StatusBarIndex=#PB_Compiler_EnumerationValue


Procedure.l Window_main()
  If OpenWindow(#Window_main,118,110,614,294,#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible,"example")
  If CreateGadgetList(WindowID(#Window_main))
      PanelGadget(#Gadget_main_Panel2,0,5,615,250)
      AddGadgetItem(#Gadget_main_Panel2,-1,"<empty>",UseImage(#Image_main_Tab))
      ListIconGadget(#Gadget_main_ListIcon8,0,10,610,215,"client #",100,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
      AddGadgetColumn(#Gadget_main_ListIcon8,1,"reference #",200)
      AddGadgetColumn(#Gadget_main_ListIcon8,2,"invoice #",90)
      AddGadgetColumn(#Gadget_main_ListIcon8,3,"value",110)
      AddGadgetColumn(#Gadget_main_ListIcon8,4,"date",80)
      CloseGadgetList()
      CreateStatusBar(#StatusBar_main,WindowID(#Window_main))
      AddStatusBarField(200)
      AddStatusBarField(300)
      HideWindow(#Window_main,0)
      ProcedureReturn WindowID()
    EndIf
  EndIf
EndProcedure

Global Color1.l, Color2.l, Tab_Count.l

Color1=RGB(224,235,255)
Color2=RGB(255,255,255)


Procedure WindowCallBack(WindowId,Message,wParam,lParam)
  ReturnValue=#PB_ProcessPureBasicEvents
  
  ReturnValue = PureLVSORT_CallBack(WindowId, Message, wParam, lParam, ReturnValue)
  ReturnValue = PureCOLOR_CallBack(WindowId, Message, wParam, lParam, ReturnValue)
  
  ProcedureReturn ReturnValue
EndProcedure

;-Main Loop
If Window_main()
  
  PureCOLOR_SetGadgetColorEx(#Gadget_main_ListIcon8, RGB(0,0,0), Color1, Color2, #PureCOLOR_LV_AlternateColors)
  
  If PureLVSORT_SelectGadgetToSort(#Gadget_main_ListIcon8, #PureLVSORT_ShowClickedHeader_Icon) = #PureLVSORT_Ok
    PureLVSORT_SetColumnType(#Gadget_main_ListIcon8, 0, #PureLVSORT_Numeric)
    PureLVSORT_SetColumnType(#Gadget_main_ListIcon8, 1, #PureLVSORT_Numeric)
    PureLVSORT_SetColumnType(#Gadget_main_ListIcon8, 2, #PureLVSORT_Numeric)
    PureLVSORT_SetColumnType(#Gadget_main_ListIcon8, 3, #PureLVSORT_String)
    PureLVSORT_SetColumnType(#Gadget_main_ListIcon8, 4, #PureLVSORT_DateDDMMYYYY)
  EndIf
  
  SetWindowCallback(@WindowCallBack())

  For a=1 To 100
    AddGadgetItem(#Gadget_main_ListIcon8,-1,Str(Random(150000)))
  Next
  
  quitmain=0
  Repeat
    EventID=WaitWindowEvent()
    Select EventID
      Case #PB_Event_CloseWindow
        If EventWindowID()=#Window_main
          quitmain=1
        EndIf
        
      Case #PB_Event_Menu
        
      Case #PB_Event_Gadget
        Select EventGadgetID()
          Case #Gadget_main_Tab
          Case #Gadget_main_ListIcon8
            Select EventType()
              Case #PB_EventType_LeftDoubleClick
              Case #PB_EventType_RightDoubleClick
              Case #PB_EventType_RightClick
              Default
            EndSelect
        EndSelect
        
    EndSelect
  Until quitmain
  CloseWindow(#Window_main)
EndIf
End
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Sorry :oops:
I forgot about this : the icons are images #0 and #1.
I will see what I can do to not interfere with the main program
Last edited by gnozal on Wed Dec 08, 2004 5:06 pm, edited 1 time in total.
ebs
Enthusiast
Enthusiast
Posts: 530
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

gnozal,
I forgot about this : the icons are images #0 and #1.
I realize you don't want to interfere with the main program, but having known image numbers would allow me to use my own up/down icons. If you do change it to use #PB_Any (or some other method), consider either providing the image ID numbers or a function call that I can use to change the images.

Regards,
Eric
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Library update

- fixed : missing constants in resident file
- fixed : image number problem
- added : flags #PureLVSORT_ShowClickedHeader_IconLeft and #PureLVSORT_ShowClickedHeader_IconRight

To do :
- user defined icons
- locked column
Num3
PureBasic Expert
PureBasic Expert
Posts: 2810
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Hurray!!!

:lol:
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

thanx a lot for your two libs. i make great use of them !

just a little bug :

when you specified a center or right alignment in the LV, then,
the sorting process of your lib reset the alignment to the left by default.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

i think you have to read and store the listview 'styles' before processing it with your code...
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Post Reply